Skip to content

stream: add isDisturbed helper#39628

Closed
ronag wants to merge 6 commits into
nodejs:masterfrom
nxtedition:is-disturbed
Closed

stream: add isDisturbed helper#39628
ronag wants to merge 6 commits into
nodejs:masterfrom
nxtedition:is-disturbed

Conversation

@ronag

@ronag ronag commented Aug 2, 2021

Copy link
Copy Markdown
Member

Adds a helper util used to determine whether a stream has been
disturbed (read or cancelled).

Refs: #39627

@ronag ronag added stream Issues and PRs related to the stream subsystem. web streams labels Aug 2, 2021
@nodejs-github-bot nodejs-github-bot added the needs-ci PRs that need a full CI run. label Aug 2, 2021

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Good for me! It needs docs and tests

@targos targos added the semver-minor PRs that contain new features and should be released in the next minor version. label Aug 2, 2021
@ronag

ronag commented Aug 2, 2021

Copy link
Copy Markdown
Member Author

@mcollina added

@ronag ronag requested a review from mcollina August 2, 2021 12:25

@mcollina mcollina left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@ronag ronag added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. and removed needs-ci PRs that need a full CI run. labels Aug 2, 2021
@github-actions github-actions Bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Aug 2, 2021
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment thread doc/api/stream.md Outdated
ronag added 2 commits August 2, 2021 15:36
Adds a helper util used to determine whether a stream has been
disturbed (read or cancelled).

Refs: nodejs#39627
@nodejs-github-bot

Copy link
Copy Markdown
Collaborator

Comment thread lib/internal/streams/readable.js Outdated
@ronag ronag requested review from benjamingr and mcollina August 3, 2021 07:34
@ronag

ronag commented Aug 3, 2021

Copy link
Copy Markdown
Member Author

@nodejs/streams this needed some additional changes to make things consistent. PTAL.

Comment thread doc/api/stream.md
* `signal` {AbortSignal}
* Returns: {stream.Readable}

### `stream.Readable.isDisturbed(stream)`

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think the name here could be more expressive, maybe .hasEmittedStreamEvents()? I know it's generic, but so is "disturbed", and it's a bit more precise.

We should also add to the documentation that this only starts being true when data has been emitted (i.e. stream.on('data'), not when data has been requested from the underlying resource (i.e. stream._read()) or made available to the stream implementation (i.e. stream.push()).

@ronag ronag Aug 3, 2021

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I think the name here could be more expressive, maybe .hasEmittedStreamEvents()? I know it's generic, but so is "disturbed", and it's a bit more precise.

I disagree. It's not just when it has been read, it's also when it has been cancelled/aborted. The WHATWG spec calls this state disturbed. Why make up a different name?

We should also add to the documentation that this only starts being true when data has been emitted (i.e. stream.on('data'), not when data has been requested from the underlying resource (i.e. stream._read()) or made available to the stream implementation (i.e. stream.push()).

I think that it is kind of clear. Neither push nor _read "reads" from the Readable interface. Anyway I'm open for suggestions...

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why make up a different name?

The argument is: Because the spec naming isn't typically meant for end-users and streams are very confusing to most of our users anyway basically.

@ronag

ronag commented Aug 4, 2021

Copy link
Copy Markdown
Member Author

This can land per se. @mscdex @addaleax are you blocking in regards to the naming?

@jasnell

jasnell commented Aug 4, 2021

Copy link
Copy Markdown
Member

I prefer to keep the current naming that is consistent with the spec language. It makes for less cognitive load when going between the two models and makes it clear that they share a common intent and purpose.

@addaleax

addaleax commented Aug 4, 2021

Copy link
Copy Markdown
Member

@ronag No. I still think it’s a confusind and unhelpful name, though.

I understand @jasnell’s point, but how many people actually do interact with the spec in the way and the frequency that you do?

@ronag

ronag commented Aug 4, 2021

Copy link
Copy Markdown
Member Author

@ronag No. I still think it’s a confusind and unhelpful name, though.

Do you have any alternative suggestions?

I understand @jasnell’s point, but how many people actually do interact with the spec in the way and the frequency that you do?

I would expect the people that would actually use this API to be quite likely to interact with the spec...

@ronag

ronag commented Aug 4, 2021

Copy link
Copy Markdown
Member Author

An alternative (that the spec also uses) is bodyUsed. However, I think the spec people themselves are unhappy with that one.

@olingern

olingern commented Aug 5, 2021

Copy link
Copy Markdown

Just as an onlooker to this PR, I wasn't familiar with a stream being "disturbed" until I went and read the spec, but I can understand @addaleax's suggestion, hasEmittedStreamEvents, instantly without understanding the underlying mechanism. Obvious trade-offs there.

I think this is more about ergonomics and what Node intends to provide to end users rather than clarity / good naming. Is there a set of "guiding principles" for this sort of thing?

ronag added a commit that referenced this pull request Aug 6, 2021
Adds a helper util used to determine whether a stream has been
disturbed (read or cancelled).

Refs: #39627

PR-URL: #39628
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
@ronag

ronag commented Aug 6, 2021

Copy link
Copy Markdown
Member Author

Landed in 4832d1c

@danielleadams

Copy link
Copy Markdown
Contributor

@ronag Can you backport this to v16.x-staging? thanks!

@ronag ronag self-assigned this Aug 16, 2021
ronag added a commit to nxtedition/node that referenced this pull request Aug 20, 2021
Adds a helper util used to determine whether a stream has been
disturbed (read or cancelled).

Refs: nodejs#39627

PR-URL: nodejs#39628
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
ronag added a commit to nxtedition/node that referenced this pull request Aug 20, 2021
Adds a helper util used to determine whether a stream has been
disturbed (read or cancelled).

Refs: nodejs#39627

PR-URL: nodejs#39628
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Backport-PR-URL: nodejs#39819
@ronag

ronag commented Aug 20, 2021

Copy link
Copy Markdown
Member Author

@danielleadams #39819

ronag added a commit to nxtedition/node that referenced this pull request Aug 20, 2021
Adds a helper util used to determine whether a stream has been
disturbed (read or cancelled).

Refs: nodejs#39627

PR-URL: nodejs#39628
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Backport-PR-URL: nodejs#39819
targos pushed a commit that referenced this pull request Aug 23, 2021
Adds a helper util used to determine whether a stream has been
disturbed (read or cancelled).

Refs: #39627

PR-URL: #39628
Backport-PR-URL: #39819
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
targos added a commit that referenced this pull request Aug 25, 2021
Notable changes:

doc:
  * deprecate type coercion for `dns.lookup` options (Antoine du Hamel) #38906
stream:
  * (SEMVER-MINOR) add `stream.Duplex.from` utility (Robert Nagy) #39519
  * (SEMVER-MINOR) add `isDisturbed` helper (Robert Nagy) #39628
util:
  * (SEMVER-MINOR) expose `toUSVString` (Robert Nagy) #39814

PR-URL: #39875
targos added a commit that referenced this pull request Aug 25, 2021
Notable changes:

doc:
  * deprecate type coercion for `dns.lookup` options (Antoine du Hamel) #38906
stream:
  * (SEMVER-MINOR) add `stream.Duplex.from` utility (Robert Nagy) #39519
  * (SEMVER-MINOR) add `isDisturbed` helper (Robert Nagy) #39628
util:
  * (SEMVER-MINOR) expose `toUSVString` (Robert Nagy) #39814

PR-URL: #39875
wwwzbwcom pushed a commit to wwwzbwcom/node that referenced this pull request Aug 26, 2021
Notable changes:

doc:
  * deprecate type coercion for `dns.lookup` options (Antoine du Hamel) nodejs#38906
stream:
  * (SEMVER-MINOR) add `stream.Duplex.from` utility (Robert Nagy) nodejs#39519
  * (SEMVER-MINOR) add `isDisturbed` helper (Robert Nagy) nodejs#39628
util:
  * (SEMVER-MINOR) expose `toUSVString` (Robert Nagy) nodejs#39814

PR-URL: nodejs#39875
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

author ready PRs that have at least one approval, no pending requests for changes, and a CI started. semver-minor PRs that contain new features and should be released in the next minor version. stream Issues and PRs related to the stream subsystem. web streams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants