-
Notifications
You must be signed in to change notification settings - Fork 30.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
stream: add isDisturbed helper #39628
Conversation
There was a problem hiding this comment.
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
@mcollina added |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
Adds a helper util used to determine whether a stream has been disturbed (read or cancelled). Refs: nodejs#39627
@nodejs/streams this needed some additional changes to make things consistent. PTAL. |
@@ -2046,6 +2057,18 @@ added: REPLACEME | |||
* `signal` {AbortSignal} | |||
* Returns: {stream.Readable} | |||
|
|||
### `stream.Readable.isDisturbed(stream)` |
There was a problem hiding this comment.
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()
).
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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.
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. |
Do you have any alternative suggestions?
I would expect the people that would actually use this API to be quite likely to interact with the spec... |
An alternative (that the spec also uses) is |
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, 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? |
Landed in 4832d1c |
@ronag Can you backport this to |
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>
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
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
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
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
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
Adds a helper util used to determine whether a stream has been
disturbed (read or cancelled).
Refs: #39627