Socket
Socket
Sign inDemoInstall

flozz-pipejs

Package Overview
Dependencies
0
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    flozz-pipejs

Simply queue asynchrone jobs in javascript


Version published
Maintainers
1
Install size
10.7 kB
Created

Readme

Source

Pipe.js

Build Status NPM Version License

This lib is deprecated, do not use it in new projects: use Promises instead. This lib will remain on NPM for compatibility purpose.

Pipe

Simply queue asynchrone jobs.

Create a Pipe

New Pipe

var p = new Pipe(
    function() {},         // Success Callback
    function() {},         // Error Callback
    function(progress) {}  // Progress callback
);

Add a job

Simple job:

p.add(function(pipe) {
    // Job code here...
});

Job with an argument:

p.add(function(pipe, arg) {
    // Job code here...
}, "argument");

Add multiple job in one round

You can add multiple jobs whose share the same code but that will receive different arguments:

p.addAll(function(pipe, arg) {
    // Job code here...
}, ["arg1", "arg2", "arg3"]);

This add 3 jobs and is equivalent to:

p.add(function(pipe, arg) {
    // Job code here...
}, "arg1");

p.add(function(pipe, arg) {
    // Job code here...
}, "arg2");

p.add(function(pipe, arg) {
    // Job code here...
}, "arg3");

Run the pipe

Once all jobs are in the Pipe, you can run it:

p.run()

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 the successCallback function if it is the last job.
  • pipe.error(): must be called if an error occurred (this will stop the Pipe and call the errorCallback). Any argument passed to this function will be forwarded to the errorCallback 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;
}

Keywords

FAQs

Last updated on 19 Jul 2016

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc