-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
Readable._construct behaviour contradicts docs #39992
Comments
It is not made explicit but you either return a promise or call the callback, not both. |
Maybe docs could be improved to be more explicit about this. |
This "feature" was introduced by #34416 (technically via 744a284). It includes both They all check if the method is a thenable, then loosely callbackifies it. For example, for node/lib/internal/streams/destroy.js Lines 288 to 305 in 253f934
Unless I'm reading this wrong, I wonder how the Duplex tests are passing (are they?) since they use both node/test/parallel/test-stream-construct-async-error.js Lines 66 to 70 in afe460e
Aside, I also noticed that
I'm having trouble figuring out of this is a supported feature / public API, or us stream implementers just got lucky. It is not documented anywhere, yet all the issues/commits/PRs I'm finding discuss it like it is an existing/known feature and there is a test suite available.
Do you mean it is a signature with a stability index of 2 ("stable")? |
Version
v16.8.0
Platform
Microsoft Windows NT 10.0.19043.0 x64
Subsystem
stream
What steps will reproduce the bug?
Returning a promise from
Readable._construct
has the same effect as calling the callback. This is not documented and may be a bug?This leads to the following strange behaviour:
Output:
Similarly:
Output:
How often does it reproduce? Is there a required condition?
Always
What is the expected behavior?
Flow should not proceed to
Readable._read
until after the callback passed toReadble._construct
has been called.The docs state:
What do you see instead?
Readable._read
despite the callback not being called yet.Additional information
It is desirable to be able to be able to use
await
withinReadable._construct
, but labelling this function asasync
(and therefore returning a Promise) appears to cause thecallback
function to be implicitly called (which is sometimes unwanted).As a workaround, I can return my own Promise from
Readable._construct
and use its resolve/reject functions in lieu of the callback.In summary, either this is expected behaviour and the docs are incorrect - or vice versa. It's hard to tell.
The text was updated successfully, but these errors were encountered: