water-fall
v1.2.0
Published
waterfall tool
Downloads
3
Readme
water-fall
所有的fn签名都是
fn = (hooks, callback) ->
xxx (err, vv) ->
hooks.vv = vv
callback null # 正常情况 顺序执行
# callback new Error 忽略之后的步骤, 直接进入 exec
wf = waterFall.create {}
wf.push (hooks, callback) ->
xxx (err, vv) ->
return callback err if err
hooks.vv = vv
callback err
wf.push (hooks, callback) ->
console.log hooks.vv # 可以读取上步的结果
callback()
cond = (hooks) -> hooks.foo
wf.pushIf cond, (hooks, callback) -> # 等效如下的写法
...
callback()
wf.push (hooks, callback) ->
return callback() if not hooks
...
callback()
wf.parallel [fn1, fn2] # 等效 push(fn1); push(fn2), 但 fn1, fn2 是同时执行, 没有先后顺序, 都正常执行完成后才进入下一步
wf.any [fn1, fn2] # 同时执行fn1, fn2; 只有都 callback err 才会当做出错处理
wf.exec (err, hooks) ->
add alias push
run alias exec
parallel alias all