Flow
"Flow" is a simple way to write readable asynchronous code using just callbacks.
Warning: this software got the stable version and will not be supported anymore. The author decided to replace this lib by another, more powerful one (brief-async).
This lib is used by Notekeeper which is also discontinued.
Usage
const Flow = ;const mainFlow = ;mainFlowsteps = 'start': getConfig 'config is OK': checkDataBase 'database is OK': getInterface 'interface is ready': renderInterface // ...mainFlowstart; { // ...
mainFlow.steps
is a list of steps of your app's execution.
The App's execution starts by mainFlow.start()
. A function done
summarizes the current step.
A result of the finished step may be specified in the second argument of a done
callback:
{ let interface = {}; // some actions ... ;}
This result will be transmitted to the next function (it's renderInterface
in this case):
{ console; // ... ;}
.
Steps
A finished step may execute several functions asynchronously:
mainFlowsteps = 'start': getConfig 'config is OK': checkDataBase getInterface // ...
.
Asynchronous race
Beware of setting one function as a result of several different steps:
mainFlowsteps = 'file 1 is read': mixFiles 'file 2 is read': mixFiles
A function may depend on data received from different asynchronous sources mixFiles (file1, file2)
. Flow does not handle this case. You may store that data somewhere and check it manually.
.
A Constructor parameters
Flow
accepts an Object with settings as an argument.
const defParams = isLogging: true // steps logging is turned on isErrors: true // errors logging is turned on logStyle: '\x1b[32m%s\x1b[0m' // green font color (Node.js) errStyle: '\x1b[31m%s\x1b[0m' // red font color (Node.js) logName: '--> ' // a prefix before each log messageconst mainFlow = defParams;
Methods
.done(stepName, results)
-- marks the current step as finished and calls functions of the next step.
.start(initialData)
-- starts the flow execution (tha same as .done('start')
).