bluebird中的Promise.all()方法的疑问
发布于 10 年前 作者 marsbaiyun 10582 次浏览 最后一次编辑是 8 年前 来自 问答

具体代码块儿大概如下所示:

request.getAsync(option)
.spread(function(res, content){
	//step 1
	var queue = [];
	queue.push(request.postAsync(option1));
	queue.push(request.postAsync(option2));
	Promise.all(queue).then(function(){
	//step 2 : do sth with arguments
	
	});
}).spread(function(res, content){
	//step 3
}).error(function(e){//...})

现在问题是程序走到step1之后直接就跳到step3了,压根儿不进step2,这是怎么回事儿啊?

2 回复

明白了,当all(queue)中的任务执行完成之后才会到step2,我应该把then换成spread

应该不是这个原因吧,1楼代码是step1做完后,step3和step2是并发执行的,你需要return Promise.all(queue)

回到顶部