tflow - t(ask)flow.
Runs an array of functions in series, each passing their results to the next in the array. However, if any of the functions pass an error to the callback, the next function is not executed and the callback is immediately called with the error.
Does same thing as async-waterflow or async.waterflow but
tasks use this
as callback instead of last argument. It has several
advantages:
- All tasks use same
this
object that references current task flow, so you can use it as temporary storage of task results and exchange results between tasks. - You don't need to declare callback for each task and always use
this
instead. - You can use this.next and this.fail for better readibility and automaticaly wrapping of string errors to errors with stacktraces.
- It's possible to log all application callback errors in single place.
Example of usage:
var tflow = { var guid; }
TFlow can be used with ES6 arrow functions too. Such functions use lexical
this
and don't allow to change it in apply
or call
, so we need to save
reference to the flow and use it instead this
.
Same technique can be used with normal javascript functions as well if you prefer
to reference flow using local variable instead of this
.
Example:
var flow = ;