Closed
Description
Version
v18.14.1
Platform
Linux 703748a51615 5.18.8-051808-generic #202206290850 SMP PREEMPT_DYNAMIC Wed Jun 29 08:59:08 UTC 2022 x86_64 Linux
Subsystem
stream
What steps will reproduce the bug?
const stream = require("node:stream");
const consumers = require("node:stream/consumers");
const createInnerTransfrom = () => new stream.Transform({
objectMode: true,
construct(callback) {
this.push('header from constructor\n');
callback();
},
transform: (row, encoding, callback) => {
callback(null, JSON.stringify(row) + '\n');
},
});
const createOuterTransfrom = () => {
let innerTranfrorm;
return new stream.Transform({
objectMode: true,
transform(row, encoding, callback) {
if (!innerTranfrorm) {
innerTranfrorm = createInnerTransfrom();
innerTranfrorm.on('data', (data) => this.push(data));
callback();
}
else if (innerTranfrorm.write(row)) {
process.nextTick(callback);
}
else {
innerTranfrorm.once('drain', callback);
}
},
});
};
consumers.text(stream.Readable.from([
'create InnerTransform',
'firstLine',
'secondLine',
]).pipe(createOuterTransfrom())).then((text) => console.log('output:\n', text));
How often does it reproduce? Is there a required condition?
always
What is the expected behavior?
output:
header from constructor
"firstLine"
"secondLine"
What do you see instead?
output:
header from constructor
"secondLine"
"firstLine"
Additional information
I expect Transform
to always process incoming items in order, even with reckless code like in the example.