forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
stream: make readable & writable computed
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: nodejs#29377
- Loading branch information
Showing
8 changed files
with
140 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'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()); | ||
r.on('error', common.mustCall(() => { | ||
assert.strictEqual(r.readable, false); | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
'use strict'; | ||
const common = require('../common'); | ||
const assert = require('assert'); | ||
|
||
const { Writable } = require('stream'); | ||
|
||
{ | ||
const w = new Writable({ | ||
write() {} | ||
}); | ||
assert.strictEqual(w.writable, true); | ||
w.destroy(); | ||
assert.strictEqual(w.writable, false); | ||
} | ||
|
||
{ | ||
const w = new Writable({ | ||
write: common.mustCall((chunk, encoding, callback) => { | ||
callback(new Error()); | ||
}) | ||
}); | ||
assert.strictEqual(w.writable, true); | ||
w.write('asd'); | ||
assert.strictEqual(w.writable, false); | ||
w.on('error', common.mustCall()); | ||
w.destroy(); | ||
} | ||
|
||
{ | ||
const w = new Writable({ | ||
write: common.mustCall((chunk, encoding, callback) => { | ||
process.nextTick(() => { | ||
callback(new Error()); | ||
assert.strictEqual(w.writable, false); | ||
}); | ||
}) | ||
}); | ||
w.write('asd'); | ||
w.on('error', common.mustCall()); | ||
} | ||
|
||
{ | ||
const w = new Writable({ | ||
write: common.mustNotCall() | ||
}); | ||
assert.strictEqual(w.writable, true); | ||
w.end(); | ||
assert.strictEqual(w.writable, false); | ||
} |