https://github.com/regular/progress-pipeline
like async.series but with a readable-stream interface for progress events
https://github.com/regular/progress-pipeline
Last synced: 8 months ago
JSON representation
like async.series but with a readable-stream interface for progress events
- Host: GitHub
- URL: https://github.com/regular/progress-pipeline
- Owner: regular
- Created: 2015-05-12T19:49:23.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-05-20T16:17:40.000Z (almost 11 years ago)
- Last Synced: 2024-04-25T15:22:14.003Z (about 2 years ago)
- Language: JavaScript
- Size: 152 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: readme.md
Awesome Lists containing this project
README
progress-pipeline
===
Like async.series, but with a readable-stream interface for getting progress events.
Installation
---
```
npm install progress-pipeline
```
Usage
---
``` javascript
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](http://fredkschott.com/post/2014/03/understanding-error-first-callbacks-in-node-js/) 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](./demo.js) for an example.
Events
---
You get two `data` events per job
* one when the job has started
```
{
jobFinished: false,
job:
jobIndex:
totalJobs:
}
```
* and one when the job has finished
```
{
jobFinished: true,
job:
jobIndex:
totalJobs:
result:
}
```
In case a job fails, the stream emits an `error` event.
The emitted error has the following additional properties:
```
{
job:
jobIndex:
totalJobs:
}
```