Pipe.js
This lib is deprecated, do not use it in new projects: use Promises instead. This lib will remain on NPM for compatibility purpose.
Simply queue asynchrone jobs.
Create a Pipe
New Pipe
var p = {} // Success Callback {} // Error Callback {} // Progress callback;
Add a job
Simple job:
p;
Job with an argument:
p;
Add multiple job in one round
You can add multiple jobs whose share the same code but that will receive different arguments:
p;
This add 3 jobs and is equivalent to:
p; p; p;
Run the pipe
Once all jobs are in the Pipe, you can run it:
p
NOTE: Any argument passed to the run()
method will be forwarded to the
first job.
About jobs and pipe object
Jobs are just Javascript functions. Each job receive a pipe
object as first
parameter.
The pipe
object provides two useful functions:
pipe.done()
: must be called when the job is done (this will start the next job). Any argument passed to this function will be forwarded to the next job or to thesuccessCallback
function if it is the last job.pipe.error()
: must be called if an error occurred (this will stop the Pipe and call theerrorCallback
). Any argument passed to this function will be forwarded to theerrorCallback
function.
Example of Job:
function job(pipe, url) { var img = new Image(); img.onload = function() { pipe.done(img); } img.onerror = function(error) { pipe.error(error); } img.src = url;}