Promise.all().then() resolve?

前端 未结 3 558
隐瞒了意图╮
隐瞒了意图╮ 2020-11-30 20:11

Using Node 4.x. When you have a Promise.all(promises).then() what is the proper way to resolve the data and pass it to the next .then()?

I

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-11-30 20:50

    Your return data approach is correct, that's an example of promise chaining. If you return a promise from your .then() callback, JavaScript will resolve that promise and pass the data to the next then() callback.

    Just be careful and make sure you handle errors with .catch(). Promise.all() rejects as soon as one of the promises in the array rejects.

提交回复
热议问题