Skip to content

Instantly share code, notes, and snippets.

@sstur
Last active July 17, 2022 15:29
Show Gist options
  • 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