Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refs: nodejs#29314
Some streams need to first asynchronously create resources before they can perform any work. Currently this is implemented in the different stream implementations which both makes things partly duplicated, more difficult, more error prone and often incorrect to some degree (e.g.
'open'
and'ready'
are emitted after'close'
).This PR provides a standardized way of asynchronously constructing streams and handles the "pending" state that occurs until construction has either completed or failed.
This will allow further simplification and improved consistency for various stream implementations such as
fs
andnet
stream.Passes the graceful-fs test suite.
This will make it possible to easily implement more complex stream such as e.g. fs streams:
Furthermore it makes it easier to e.g. add transforms into pipeline by inlining initialization:
Semver
fs
: Don't emit'open'
afterdestroy()
. See updated test. Bug fix.fs
: Emit some previously synchronous errors asynchronously. See updated test. Bug fix.fs
:open()
is removed but it still works if monkey-patched. Deprecation.Otherwise, this should be pretty non breaking as far as I can tell.
graceful-fs
tests pass and there are tests for compat.The changes are mostly opt-in through the
construct
method, except for the previously listed updates tofs
streams.Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passesNOTE TO SELF: After merge look into:
emitClose
and make'close'
behaviour align with streams.close(cb)
in favour ofend(cb)
. Makeclose(cb)
callend(cb)
.