stream: implement finished() for ReadableStream and WritableStream#46205
stream: implement finished() for ReadableStream and WritableStream#46205nodejs-github-bot merged 16 commits intonodejs:mainfrom
Conversation
|
Review requested:
|
d99602f to
e036f56
Compare
|
So far now its not breaking any more tests hence opening the PR for review |
| throw new ERR_INVALID_THIS('ReadableStream'); | ||
| return this[kState].streamClosed.promise; | ||
| } | ||
|
|
There was a problem hiding this comment.
You can't add new public properties to web streams. That is not allowed by the spec.
There was a problem hiding this comment.
ok updating this to private access?
There was a problem hiding this comment.
Have updated to access using [kState]
mcollina
left a comment
There was a problem hiding this comment.
Can you please add some more tests for error conditions? You'd also need tests for Duplex too.
Understood trying to add the same! |
| PromisePrototypeThen( | ||
| stream[kState].streamClosed, | ||
| () => callback.call(stream), | ||
| (err) => callback.call(stream, err) |
There was a problem hiding this comment.
You need to call the callback with a process.nextTick
There was a problem hiding this comment.
fixed this to properly use process.nextTick
| function readableStreamClose(stream) { | ||
| assert(stream[kState].state === 'readable'); | ||
| stream[kState].state = 'closed'; | ||
| stream[kState].streamClosed?.resolve?.(); |
There was a problem hiding this comment.
I think it can because initially when I tested without null checks it failed
There was a problem hiding this comment.
Then I think there might be a bug somewhere. What does it mean when it's nully?
There was a problem hiding this comment.
Okay trying to investigate
There was a problem hiding this comment.
Fixed this, removed the null checks basically it was breaking tests where tee() was being used to construct streams
|
Have added a number of tests on the error conditions and promises on both readable & writable streams,
Didn't get you here? |
|
Reopening the PR again for review, it seems stable now |
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Notable changes: * deps: * upgrade npm to 9.3.1 (npm team) #46242 * doc: * add parallelism note to os.cpus() (Colin Ihrig) #45895 * http: * join authorization headers (Marco Ippolito) #45982 * improved timeout defaults handling (Paolo Insogna) #45778 * stream: * implement finished() for ReadableStream and WritableStream (Debadree Chatterjee) #46205 PR-URL: #46396
Notable changes: * deps: * upgrade npm to 9.3.1 (npm team) #46242 * doc: * add parallelism note to os.cpus() (Colin Ihrig) #45895 * http: * join authorization headers (Marco Ippolito) #45982 * improved timeout defaults handling (Paolo Insogna) #45778 * stream: * implement finished() for ReadableStream and WritableStream (Debadree Chatterjee) #46205 PR-URL: #46396
Notable changes: * deps: * upgrade npm to 9.3.1 (npm team) #46242 * doc: * add parallelism note to os.cpus() (Colin Ihrig) #45895 * http: * join authorization headers (Marco Ippolito) #45982 * improved timeout defaults handling (Paolo Insogna) #45778 * stream: * implement finished() for ReadableStream and WritableStream (Debadree Chatterjee) #46205 PR-URL: #46396
Notable changes: * deps: * upgrade npm to 9.3.1 (npm team) #46242 * doc: * add parallelism note to os.cpus() (Colin Ihrig) #45895 * http: * join authorization headers (Marco Ippolito) #45982 * improved timeout defaults handling (Paolo Insogna) #45778 * stream: * implement finished() for ReadableStream and WritableStream (Debadree Chatterjee) #46205 PR-URL: #46396
PR-URL: nodejs#46312 Refs: nodejs#46190 Refs: nodejs#46205 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Refs: nodejs#46205 PR-URL: nodejs#46403 Refs: nodejs#37354 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
PR-URL: nodejs#46312 Refs: nodejs#46190 Refs: nodejs#46205 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Refs: nodejs#46205 PR-URL: nodejs#46403 Refs: nodejs#37354 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
PR-URL: nodejs#46312 Refs: nodejs#46190 Refs: nodejs#46205 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Refs: nodejs#46205 PR-URL: nodejs#46403 Refs: nodejs#37354 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Robert Nagy <ronagy@icloud.com>
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
kanongil
left a comment
There was a problem hiding this comment.
While it is nice to be able to know when a stream has closed, I'm not a fan of this feature.
It will be cumbersome (impossible?) to implement in readable-stream for browser usage since it will need to rely on the public WebStreams API.
| if (isReadableStream(stream) || isWritableStream(stream)) { | ||
| return eosWeb(stream, options, callback); | ||
| } |
There was a problem hiding this comment.
These match non-node WebStreams – which I guess is fine, except that eosWeb() will throw a TypeError since the private property kIsClosedPromise will not exist on it. This will in turn mean that the callback is never called.
There was a problem hiding this comment.
As in you want eosWeb to additionally have a check to throw TypeError ?
There was a problem hiding this comment.
I don't know what node should do – probably still throw some kind of error.
Currently non-node WebStreams would just throw a TypeError from accessing the promise property on the undefined kIsClosedPromise property here:
node/lib/internal/streams/end-of-stream.js
Line 289 in 4667b07
PR-URL: nodejs#46312 Refs: nodejs#46190 Refs: nodejs#46205 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Backport-PR-URL: #46314 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
PR-URL: nodejs#46312 Backport-PR-URL: nodejs#46314 Refs: nodejs#46190 Refs: nodejs#46205 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Backport-PR-URL: nodejs#46314 Reviewed-By: Robert Nagy <ronagy@icloud.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com> Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Anna Henningsen <anna@addaleax.net>
Implemented finished() for ReadableStreams and WritableStreams and added tests.
Refs: #39316