例如采取以下代码:
getThing = (thing_id, cb_success, cb_error) ->
model.findById thing_id,
(error, thing) ->
if error || !thing
cb_error "error"
else
cb_success thing
然后调用函数
getThing thing_id
, (thing) ->
console.log "Found a thing!"
, (error)
console.log" Uh oh..."
如果我要传递多个回调,但都不能保证会被调用,那么我该如何为这种情况构建 await/defer?或者我是否需要完全重新考虑我的代码以仅提供一个回调,然后评估其中是否存在错误?