How to use it
Let start with a basic example. 2 jobs run in sequence. The first job is a timeout so the result is delivered asynchronously, and a second job is run only after the completion of the first.
1 2 3 4 5 6 7 8 9
It will display the following
step 1: started, it will last 1sec step 1: 1sec expired. Step 1 completed step 2: run after step1 has been completed
In order to keep it as simple as possible, Flow has only 2 methods.
.seq(callback) to execute job sequentially
.seq() is used to execute functions sequentially. The callback parameter
will be executed only after all previous jobs are completed.
The callback signature is
callback(next, error, result)
next(error, result)is the function to call when the job is completed. error is to notify an error to the next job. result to notify a result. error and result may be omitted, if so they are considered equal to
erroris the error send by previous jobs
resultis the result send by previous jobs
1 2 3 4 5 6 7
.par(callback) to execute job in parallel
.par() is used to execute functions in parallel. The callback parameter is the same as for
If multiple .par() are declared one after another, they are run in parallel. The first
.seq() after them
will receive all the error and result in Array. One array item per previous
1 2 3 4 5 6 7 8 9 10 11 12