Skip to content

docs: writable streams from async iterators example issue #31365

@ronag

Description

@ronag

Continuation of #31222

Further issues with the example. See comment:

async function pump(iterable, writable) {
  for await (const chunk of iterable) {
    // Handle backpressure on write().
    if (!writable.write(chunk)) {
      if (writable.destroyed) return;
      await once(writable, 'drain'); // BUG? This will never complete if writable is destroyed with `.destroy()`.
    }
  }
  writable.end();
}

The problem here is that it assumes that either 'drain' or 'error' will be emitted, however this is not always the case.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions