-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
42 lines (39 loc) · 1.18 KB
/
demo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
var board = require('.');
var pipeline = require('progress-pipeline');
function makeJob(name, duration, err) {
var f = function(cb) {
setTimeout(function() {cb(Math.random()>0.8?err:null);}, duration);
};
f.title = name;
return f;
}
function makeJobs(jobCount, fail) {
var jobs = [];
for(var i=0; i<jobCount; ++i) {
var duration = Math.floor(Math.random() * 4000);
var name = String.fromCharCode(65+i);
jobs.push(makeJob(name, duration, fail?new Error('this is bad!'):null));
}
return jobs;
}
board()
.add(makeJobs(8), 'first')
.add(makeJobs(8), {
template: function(ctx) {
if (
ctx._jobFinished &&
ctx._jobIndex === ctx._totalJobs-1
) {
return ' 2nd: done';
}
return '-\\|/'[ctx._jobIndex % 4] + ' 2nd';
}
})
.add(
pipeline(makeJobs(20, true)).on('error', function() {
process.stdout.write('\u0007'); // terminal BELL
})
)
.add(makeJobs(10, true), {context: {name: 'fourth', color:'yellow'}})
.on('end', function() {console.log('ALL DONE');})
.pipe(process.stdout);