Skip to content

Conversation

@debadree25
Copy link
Member

@debadree25debadree25 commented Jan 13, 2023

Implemented finished() for ReadableStreams and WritableStreams and added tests.

Refs: #39316

@nodejs-github-bot
Copy link
Collaborator

Review requested:

  • @nodejs/streams

@nodejs-github-botnodejs-github-bot added needs-ci PRs that need a full CI run. web streams labels Jan 13, 2023
@debadree25debadree25force-pushed the ft/finished-webstreams branch from d99602f to e036f56CompareJanuary 14, 2023 08:09
@debadree25
Copy link
MemberAuthor

So far now its not breaking any more tests hence opening the PR for review

@debadree25debadree25 marked this pull request as ready for review January 14, 2023 09:43
@debadree25debadree25 changed the title streams: implement finished() for webstreamsstream: implement finished() for webstreamsJan 14, 2023
thrownewERR_INVALID_THIS('ReadableStream');
returnthis[kState].streamClosed.promise;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can't add new public properties to web streams. That is not allowed by the spec.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok updating this to private access?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have updated to access using [kState]

Copy link
Member

@mcollinamcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please add some more tests for error conditions? You'd also need tests for Duplex too.

@debadree25
Copy link
MemberAuthor

Can you please add some more tests for error conditions? You'd also need tests for Duplex too.

Understood trying to add the same!

@debadree25debadree25 marked this pull request as draft January 14, 2023 11:18
@debadree25
Copy link
MemberAuthor

Converting this to a draft again, since there seems to be some work left and it seems to be more complex than I anticipated 😅 but any comments on the general approach I am taking regarding adding promises is it a good enough path? @mcollina, @ronag

PromisePrototypeThen(
stream[kState].streamClosed,
()=>callback.call(stream),
(err)=>callback.call(stream,err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to call the callback with a process.nextTick

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

understood updating

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed this to properly use process.nextTick

functionreadableStreamClose(stream){
assert(stream[kState].state==='readable');
stream[kState].state='closed';
stream[kState].streamClosed?.resolve?.();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can streamClosed be nully?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it can because initially when I tested without null checks it failed

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Then I think there might be a bug somewhere. What does it mean when it's nully?

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay trying to investigate

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed this, removed the null checks basically it was breaking tests where tee() was being used to construct streams

@debadree25
Copy link
MemberAuthor

Have added a number of tests on the error conditions and promises on both readable & writable streams,

You'd also need tests for Duplex too.

Didn't get you here?

@mcollina

@debadree25
Copy link
MemberAuthor

Reopening the PR again for review, it seems stable now

@debadree25debadree25 marked this pull request as ready for review January 14, 2023 21:03
Copy link
Member

@mcollinamcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollinamcollina added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 14, 2023
@github-actionsgithub-actionsbot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 14, 2023
@nodejs-github-bot
Copy link
Collaborator

@debadree25debadree25 changed the title stream: implement finished() for webstreamsstream: implement finished() for ReadableStream and WritableStreamJan 15, 2023
ruyadorno pushed a commit that referenced this pull request Feb 1, 2023
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
ruyadorno pushed a commit that referenced this pull request Feb 1, 2023
juanarbol added a commit that referenced this pull request Feb 1, 2023
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
juanarbol added a commit that referenced this pull request Feb 1, 2023
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
juanarbol added a commit that referenced this pull request Feb 1, 2023
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
juanarbol added a commit that referenced this pull request Feb 2, 2023
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
nodejs-github-bot pushed a commit that referenced this pull request Feb 2, 2023
Refs: #46205 PR-URL: #46403 Refs: #37354 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
MylesBorins pushed a commit that referenced this pull request Feb 18, 2023
Refs: #46205 PR-URL: #46403 Refs: #37354 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
Refs: nodejs#46205 PR-URL: nodejs#46403 Refs: nodejs#37354 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
Refs: nodejs#46205 PR-URL: nodejs#46403 Refs: nodejs#37354 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
debadree25 added a commit to debadree25/node that referenced this pull request Feb 27, 2023
Refs: nodejs#46205 PR-URL: nodejs#46403 Refs: nodejs#37354 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
juanarbol pushed a commit that referenced this pull request Mar 3, 2023
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
juanarbol pushed a commit that referenced this pull request Mar 3, 2023
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
juanarbol pushed a commit that referenced this pull request Mar 5, 2023
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
danielleadams pushed a commit that referenced this pull request Apr 11, 2023
Refs: #46205 PR-URL: #46403 Refs: #37354 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Robert Nagy <[email protected]>
Copy link
Contributor

@kanongilkanongil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +64 to +66
if(isReadableStream(stream)||isWritableStream(stream)){
returneosWeb(stream,options,callback);
}
Copy link
Contributor

@kanongilkanongilApr 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As in you want eosWeb to additionally have a check to throw TypeError ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 undefinedkIsClosedPromise property here:

stream[kIsClosedPromise].promise,

debadree25 added a commit to debadree25/node that referenced this pull request May 23, 2023
debadree25 added a commit to debadree25/node that referenced this pull request May 23, 2023
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
danielleadams pushed a commit that referenced this pull request May 29, 2023
danielleadams pushed a commit that referenced this pull request May 29, 2023
Refs: #46190 Refs: #46205 (comment) PR-URL: #46315 Backport-PR-URL: #46314 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
aduh95 pushed a commit to aduh95/node that referenced this pull request Feb 18, 2025
aduh95 pushed a commit to aduh95/node that referenced this pull request Feb 18, 2025
Refs: nodejs#46190 Refs: nodejs#46205 (comment) PR-URL: nodejs#46315 Backport-PR-URL: nodejs#46314 Reviewed-By: Robert Nagy <[email protected]> Reviewed-By: Matteo Collina <[email protected]> Reviewed-By: Darshan Sen <[email protected]> Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Anna Henningsen <[email protected]>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author readyPRs that have at least one approval, no pending requests for changes, and a CI started.commit-queue-squashAdd this label to instruct the Commit Queue to squash all the PR commits into the first one.needs-ciPRs that need a full CI run.semver-minorPRs that contain new features and should be released in the next minor version.web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants

@debadree25@nodejs-github-bot@mcollina@jasnell@kanongil@ronag@RaisinTen@aduh95