promise应该如何书写带有分支的异步操作
发布于 9 年前 作者 sjfkai 3966 次浏览 最后一次编辑是 8 年前 来自 问答

最近努力理解promise遇到了一个问题: 对于如下带有分支的异步操作

asyncFunc1(arg,function(e,res){
	if(res){
		asycnFunc2(arg,function(e,res){
			cb(null,res);
		})
	}else{
		cb(null,false);
	}
});

转换成promise的格式应该怎么写呢? 感谢

1 回复
asyncFunc1Promise arg
.then ([res])->
	if !res
		throw 'end'
	asycnFunc2Promise arg
.then ([res])->
	doSomething()
.done ([result])->
	doSomething()
, (err)->
	if err=='end'
		return	doOtherThings()
	errorHander()

回到顶部