promise在resolve以後 再拋出錯誤並不會被捕獲,等於沒有拋出,我的理解是狀態改變以後就不會再次改變。promise
getAsyncArr().then(promiseArr => { return promise.all(promiseArr); }) .then(res => console.log(res))
實現串行執行,那咱們能夠利用reduce來處理串行執行
var pA = [ function() {return new Promise(resolve => resolve(1))}, function(data) {return new Promise (resolve(1 + data))} ] pA.reduce((prev, next) => prev.then(next).then(res=>res), Promise.resolve()).then(res => console.log(res))
函數