After the Promise and async / await waiting for a value to true, the following code before execution

Scene: the method vuex need to wait for the other event trigger, such that the value haveGroupList later changed to true, you can perform the following after the code

Promise wording:

getData(){
    let r = new Promise((resolve) =>{
      let timer = setInterval(() =>{
          if(this.haveGroupList === true){
            clearInterval(timer)
            resolve(true)
          }
      },100)
    })
            
     r.then((res) =>{
        console.log('ddddddddddddddo somting')
            ...
    })
}
        

async / await wording:

async getData(){
    await new Promise( (resolve) =>{
      let timer = setInterval(() =>{
          if(this.haveGroupList === true){
              clearInterval(timer)
              resolve(true)
          }
      },100)
    })
    
    console.log('ddddddddddddddo somting')
    ...  

}

 

Guess you like

Origin www.cnblogs.com/Naiky/p/12404488.html