How to structure nested Promises

前端 未结 3 1089
误落风尘
误落风尘 2020-11-30 12:00

I have a situation where I think the only choice for me is to nest some Promises within each other. I have a Promise that needs to be performed and a method that does someth

3条回答
  •  情歌与酒
    2020-11-30 12:45

    Use .then()

    let doStuff = (resolve, reject) => {/* resolve() or reject() */};
    let promise = new Promise(doStuff);
    doSomethingUntilPromiseisDone(
      promise 
      .then(value => fetchValue(url))
      .then(value => value.blob())
      .then(saveToCache)
    )
    .then(success => console.log("success!!"))
    .catch(err => console.error(err))
    

提交回复
热议问题