promise使用的问题,求指教
发布于 8 年前 作者 tw234tw 2801 次浏览 来自 分享

使用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 回复
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); //想要在有可能出现错误的情况下,能把正常执行的显示出来。
})

@klesh 谢谢。

回到顶部