mirror of
https://github.com/nodejs/node.git
synced 2026-11-29 14:27:57 -05:00
stream: always delay construct callback by a nextTick
Signed-off-by: Matteo Collina <hello@matteocollina.com> Fixes: https://github.com/nodejs/node/issues/46765 PR-URL: https://github.com/nodejs/node/pull/46818 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
This commit is contained in:
1 parent
d896da092b
commit
355bcbc33d
2 files changed
+28
-2
No files matched your search
@@ -272,9 +272,11 @@ function constructNT(stream) {
|
||||
}
|
||||
|
||||
try {
|
||||
stream._construct(onConstruct);
|
||||
stream._construct((err) => {
|
||||
process.nextTick(onConstruct, err);
|
||||
});
|
||||
} catch (err) {
|
||||
onConstruct(err);
|
||||
process.nextTick(onConstruct, err);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -468,3 +468,27 @@ const { PassThrough, Transform } = require('stream');
|
||||
assert.strictEqual(ended, true);
|
||||
}));
|
||||
}
|
||||
|
||||
{
|
||||
const s = new Transform({
|
||||
objectMode: true,
|
||||
construct(callback) {
|
||||
this.push('header from constructor');
|
||||
callback();
|
||||
},
|
||||
transform: (row, encoding, callback) => {
|
||||
callback(null, row);
|
||||
},
|
||||
});
|
||||
|
||||
const expected = [
|
||||
'header from constructor',
|
||||
'firstLine',
|
||||
'secondLine',
|
||||
];
|
||||
s.on('data', common.mustCall((data) => {
|
||||
assert.strictEqual(data.toString(), expected.shift());
|
||||
}, 3));
|
||||
s.write('firstLine');
|
||||
process.nextTick(() => s.write('secondLine'));
|
||||
}
|
||||
Reference in new issue
Block a user