-
Notifications
You must be signed in to change notification settings - Fork 28.2k
/
test-stream-auto-destroy.js
84 lines (67 loc) · 1.36 KB
/
test-stream-auto-destroy.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
'use strict';
const common = require('../common');
const stream = require('stream');
const assert = require('assert');
{
const r = new stream.Readable({
autoDestroy: true,
read() {
this.push('hello');
this.push('world');
this.push(null);
},
destroy: common.mustCall((err, cb) => cb())
});
let ended = false;
r.resume();
r.on('end', common.mustCall(() => {
ended = true;
}));
r.on('close', common.mustCall(() => {
assert(ended);
}));
}
{
const w = new stream.Writable({
autoDestroy: true,
write(data, enc, cb) {
cb(null);
},
destroy: common.mustCall((err, cb) => cb())
});
let finished = false;
w.write('hello');
w.write('world');
w.end();
w.on('finish', common.mustCall(() => {
finished = true;
}));
w.on('close', common.mustCall(() => {
assert(finished);
}));
}
{
const t = new stream.Transform({
autoDestroy: true,
transform(data, enc, cb) {
cb(null, data);
},
destroy: common.mustCall((err, cb) => cb())
});
let ended = false;
let finished = false;
t.write('hello');
t.write('world');
t.end();
t.resume();
t.on('end', common.mustCall(() => {
ended = true;
}));
t.on('finish', common.mustCall(() => {
finished = true;
}));
t.on('close', common.mustCall(() => {
assert(ended);
assert(finished);
}));
}