mirror of
https://github.com/nodejs/node.git
synced 2025-04-28 13:40:37 +00:00

This makes readable and writable automatically computed based on the stream state. Effectivly deprecating/discouraging manual management of this. Makes the properties more consistent and easier to reason about. Fixes: https://github.com/nodejs/node/issues/29377 PR-URL: https://github.com/nodejs/node/pull/31197 Refs: https://github.com/nodejs/node/issues/29377 Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
46 lines
928 B
JavaScript
46 lines
928 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
|
|
const { Readable } = require('stream');
|
|
|
|
{
|
|
const r = new Readable({
|
|
read() {}
|
|
});
|
|
assert.strictEqual(r.readable, true);
|
|
r.destroy();
|
|
assert.strictEqual(r.readable, false);
|
|
}
|
|
|
|
{
|
|
const mustNotCall = common.mustNotCall();
|
|
const r = new Readable({
|
|
read() {}
|
|
});
|
|
assert.strictEqual(r.readable, true);
|
|
r.on('end', mustNotCall);
|
|
r.resume();
|
|
r.push(null);
|
|
assert.strictEqual(r.readable, true);
|
|
r.off('end', mustNotCall);
|
|
r.on('end', common.mustCall(() => {
|
|
assert.strictEqual(r.readable, false);
|
|
}));
|
|
}
|
|
|
|
{
|
|
const r = new Readable({
|
|
read: common.mustCall(() => {
|
|
process.nextTick(() => {
|
|
r.destroy(new Error());
|
|
assert.strictEqual(r.readable, false);
|
|
});
|
|
})
|
|
});
|
|
r.resume();
|
|
r.on('error', common.mustCall(() => {
|
|
assert.strictEqual(r.readable, false);
|
|
}));
|
|
}
|