CNode

promise应该如何书写带有分支的异步操作

问答
Ssjfkai发布于12 年前最后回复12 年前1 回复4567 浏览0 收藏

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

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

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

查看回复

回复 (1)

S
soliury#1·12 年前
asyncFunc1Promise arg
.then ([res])->
	if !res
		throw 'end'
	asycnFunc2Promise arg
.then ([res])->
	doSomething()
.done ([result])->
	doSomething()
, (err)->
	if err=='end'
		return	doOtherThings()
	errorHander()

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