promise应该如何书写带有分支的异步操作
 发布于 11 年前  作者 sjfkai  4452 次预览  最后一次回复是 11 年前  来自 问答 

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

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

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

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