Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: async iterate readable streams, iterate function #30

Merged
merged 1 commit into from
May 3, 2018

Conversation

reconbot
Copy link
Contributor

  • async iterator on all bluestream readable streams
  • iterate(stream) any readable stream

BREAKING CHANGE: dropped the default export

- async iterator on all bluestream readable streams
- `iterate(stream)` any readable stream

BREAKING CHANGE: dropped the default export
@reconbot reconbot requested a review from tsiege April 30, 2018 21:44
import { Readable } from 'stream'
import { readAsync } from '.'

if ((Symbol as any).asyncIterator === undefined) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the syntax that's confusing me the most.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a polyfill for the asyncIterator symbol, since the type Symbol doesn't have that property we need to cast it to an any to get it pass lint

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oy

throw new TypeError('"stream" is in flowing mode, this is probably not what you want as data loss could occur. Please use stream.pause() to pause the stream before calling readAsync.');
}

const inflightRead = inflightReads.get(stream)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is some sort of buffer?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, it defers next readAsync until after the first one finishes so they don't clobber. The weakmap keys the inflight reads on the stream objects themselves and doesn't cause a memory leak like a normal Map would.

@reconbot reconbot merged commit 7c2fe7b into master May 3, 2018
@reconbot reconbot deleted the reconbot/async-iterator branch May 3, 2018 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants