Skip to content

stream: standardize async initialization #29314

Description

@ronag

Some streams (e.g.fs and net) 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 more difficult and error prone (e.g. 'open' and 'ready' are emitted after 'close'). I suggest we provide a standardized way of achieving this.

This would allow further simplification and improved consistency for various stream implementations such as fs and net stream.

I propose the following API for this:

  • a stream._construct(cb) endpoint (similar to _destroy(cb)).
  • a stream.ready property indicating whether the stream is ready (currently this is called pending in some implementations). Including readableReady and writableReady accessors.
  • a 'ready' event (currently this is called 'open' in some implementations).

See, nxtedition#2 for proof of concept.

Activity

  1. changed the title [-]stream: provide a _construct end-point for streams with async initialization.[/-] [+]stream: standardize async initialization.[/+] on Aug 25, 2019
  2. changed the title [-]stream: standardize async initialization.[/-] [+]stream: standardize async initialization[/+] on Aug 25, 2019
  3. ronag commented on Aug 25, 2019

    @ronag
    MemberAuthor

    I suggest in order to land this we first update either net or fs to as far as possible use "standardized" streams (e.g. #29048) and then try to apply this suggestion there to prove the concept.

  4. ronag commented on Sep 5, 2019

    @ronag
    MemberAuthor

    Here is a proposal implementation. Don't think I can get much further without some feedback.

    nxtedition#2

  5. 19 remaining items

  6. added 2 commits that reference this issue on May 25, 2020
  7. ronag commented on May 27, 2020

    @ronag
    MemberAuthor

    This has landed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    streamIssues and PRs related to Node.js streams.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions