CNode

promise使用的问题,求指教

分享
Ttw234tw发布于11 年前最后回复11 年前3 回复3509 浏览0 收藏

使用bluebird的promise.map方法,但是该方法只要其中一个执行被catch,整个就进入catch,正常执行的不会显示出来, 这种情况怎么用bluebird做呢?

var datas=['1','2','1','2']; Promise.map(data,function(data){ return testasync(message); }).then(function(result){ console.log(result); //想要在有可能出现错误的情况下,能把正常执行的显示出来。 }).catch(function(error){ console.log(error) })

查看回复

回复 (3)

T
tw234tw#1·11 年前
引用 klesh

@klesh 谢谢。

K
klesh#2·11 年前
var datas=['1','2','1','2'];
Promise.map(data,function(data){
	return testasync(message).catch(function(err) { // correct exception respectively, so the outer chain will not be corrupted
		return "shit happened: " + err.message
	});
}).then(function(result){
	console.log(result); //想要在有可能出现错误的情况下,能把正常执行的显示出来。
})
G
gjc9620#3·11 年前
引用 klesh

@klesh 学习了

参与回复
登录后即可参与回复。登录