-
Notifications
You must be signed in to change notification settings - Fork 1
/
pull-continue-test.js
58 lines (51 loc) · 1.52 KB
/
pull-continue-test.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* jshint -W064, -W104, -W119, -W097, -W067 */
/* jshint node: true */
"use strict";
var pcontinue = require('pull-continue');
let pull = require('pull-stream');
let makeClicker = (action) => {
return pull.asyncMap( ( () => {
console.log('i am a new stream', action);
let count = 5;
return (data, cb) => {
if (data) count--;
let doAction = count === 0;
if (doAction) {
console.log('doAction');
setTimeout( () => {
console.log('great success');
cb(null, action);
}, 300);
} else {
if (count<0) {
console.log('below 0');
setTimeout( () => {
console.log('abort');
cb(true);
}, 300);
} else {
setTimeout( () => {
console.log('no action');
cb(null, null);
}, 300);
}
}
};
})() );
};
var actions = ['action1', 'azione'];
pull(
pcontinue( (i, n) => {
if (i<actions.length) {
console.log("stream number "+ i);
return pull(
//pull.values([null,null,null,null]),
pull.values([1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]),
makeClicker(actions[i])
);
}
return;
}),
pull.filter( x => x ),
pull.log()
);