我一直在試圖讓Promise.all到與承諾的列表中沒有成功而工作,所以不是隻有一個承諾,而不是一個陣列嘗試過了,我得到了同樣的問題:Promise.all不返回
let tasks = [];
tasks.push(function(resolve, reject){
superagent
.post(URL_ROOT + url_path)
.send(data)
.end(function(err, res){
if(err)
reject(err);
assert.equal(res.status, status.UNAUTHORIZED); //401
console.log('Promise completed successfully');
resolve();
});
});
Promise.all([
new Promise(tasks[0])
]).then(function(){
console.log("Done");
done();
})
.catch(function(reason){
throw new Error(reason);
});
「承諾成功完成」打印就好,但它只是掛起,'完成'從不打印。
任何幫助將不勝感激。
這沒有意義。如果「Promise completed successfully」被打印,那麼「完成」也應該被打印。 – Lewis
請注意,如果你的斷言拋出,你的承諾永遠不會被拒絕,並且catch語句的回調沒有意義(它可能應該調用'done'並帶有錯誤) – Bergi
@Bergi我必須承認我沒有履行我的承諾像這樣,並將Promise直接添加到任務數組中。但是OP說他得到了「Promise成功完成」,所以斷言雖然錯了不能成爲這裏的問題,因爲決心肯定也會受到打擊。剝離超強的東西,確實對我有用。 OP是否可能使用某些特定的Promise庫,它不能正常工作? – Keith