Skip to content

like async.series but with a readable-stream interface for progress events

Notifications You must be signed in to change notification settings

regular/progress-pipeline

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

progress-pipeline

Like async.series, but with a readable-stream interface for getting progress events.

Installation

npm install progress-pipeline

Usage

var series = require('progress-pipeline');

var jobs =[
    function cloning(cb) {
        gitClone(user + '/' + repo, function(err) {
            cb(err, 'done cloning');
        });
    },
    function installing(cb) {
        shell('cd '+ repo +' && npm install', function(err) {
            cb(err, 'done installing');
        });
    }
];

series(jobs).on('data', function(data) {
    console.log(data.jobFinished ? data.result : data.jobIndex + '/' + data.totalJobs + data.job.name + ' ...');
});

output:

0/2 cloning ...
done cloning
1/2 installing ...
done installing

Job Functions

Jobs are regular, node-style async functions, e.g. they are being called with an error-first callback and are required to call that callback with an error and an optional result argument.

Note You can add properties to the job functions before putting them into the pipeline and you will have access to these prperties in your on('data') event handler. See demo.js for an example.

Events

You get two data events per job

  • one when the job has started
{
    jobFinished: false,
    job: <the job-function you provided>
    jobIndex: <zero-based index of this job>
    totalJobs: <total number of jobs in the pipeline>
}
  • and one when the job has finished
{
    jobFinished: true,
    job: <the job-function you provided>
    jobIndex: <zero-based index of this job>
    totalJobs: <total number of jobs in the pipeline>
    result: <the job's result>
}

In case a job fails, the stream emits an error event. The emitted error has the following additional properties:

{
    job: <the job-function you provided>
    jobIndex: <zero-based index of this job>
    totalJobs: <total number of jobs in the pipeline>
}

About

like async.series but with a readable-stream interface for progress events

Resources

Stars

Watchers

Forks

Packages

No packages published