Skip to content

Instantly share code, notes, and snippets.

@sstur
Last active July 17, 2022 15:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sstur/29d7de58d3c7073781e26b46ee397dac to your computer and use it in GitHub Desktop.
Save sstur/29d7de58d3c7073781e26b46ee397dac to your computer and use it in GitHub Desktop.

Polyfill ReadableStream making it always an async iterator:

ReadableStream.prototype[Symbol.asyncIterator] = function() {
  const reader = this.getReader();
  return {
    next: () => reader.read(),
    return: () => {
      reader.releaseLock();
    },
  };
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment