resume.js
754 Bytes
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
var test = require('tape');
var resumer = require('../');
var concat = require('concat-stream');
test('implicit resume', function (t) {
t.plan(1);
var s = createStream();
s.pipe(concat(function (err, body) {
t.equal(body, 'beep boop\n');
}));
});
test('pause/resume', function (t) {
t.plan(2);
var s = createStream();
s.pause();
var paused = true;
setTimeout(function () {
paused = false;
s.resume();
}, 100);
s.pipe(concat(function (err, body) {
t.equal(paused, false);
t.equal(body, 'beep boop\n');
}));
});
function createStream () {
var stream = resumer();
stream.queue('beep boop\n');
stream.queue(null);
return stream;
}