refactor: return an AsyncGenerator instead#1
Merged
43081j merged 2 commits intoJul 11, 2025
Conversation
42dde6d to
fda3ebc
Compare
AsyncIterator insteadAsyncGenerator instead
2df260e to
08a7741
Compare
08a7741 to
447a10f
Compare
447a10f to
4d8a61c
Compare
43081j
reviewed
Jul 11, 2025
| const iterator = api.withIterator()[Symbol.asyncIterator](); | ||
| const results: string[] = []; | ||
| const iterator = api.withIterator(); | ||
| const results: (string | void)[] = []; |
Owner
There was a problem hiding this comment.
this doesn't seem right, its going to end up an array of string | undefined i guess
what causes it to emit undefined?
Owner
There was a problem hiding this comment.
its because you should check the done property in real world
when you do, it narrows the void out
Owner
|
will merge in, if there's any changes i see, ill just do them in my branch 👍 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
returns an actual iterator instead of some class you can iterate over. this allows you to do something like
await withIterator().next(), and in the future will allow you to use async iterator helpers with no need of any code changes on the fdir side, likewithIterator().take(2).originally used
AsyncIteratorObject, replaced withAsyncGeneratorso that the.returnand.throwmethods are well defined,AsyncGeneratorextendsAsyncIteratorObjecton new ts versions anyways. this also avoids requiring ts >=5.6 like it almost did. the text below is now obsolete:this is done by using the newAsyncIteratorObjecttype from ts 5.6 https://devblogs.microsoft.com/typescript/announcing-typescript-5-6/#iterator-helper-methods. it currently is identical toAsyncIteratorbut will have support for async iterator helpers