Skip to content

refactor: return an AsyncGenerator instead#1

Merged
43081j merged 2 commits into
43081j:iterator-madnessfrom
SuperchupuDev:chore/async-iterator
Jul 11, 2025
Merged

refactor: return an AsyncGenerator instead#1
43081j merged 2 commits into
43081j:iterator-madnessfrom
SuperchupuDev:chore/async-iterator

Conversation

@SuperchupuDev
Copy link
Copy Markdown

@SuperchupuDev SuperchupuDev commented Jul 5, 2025

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, like withIterator().take(2).

originally used AsyncIteratorObject, replaced with AsyncGenerator so that the .return and .throw methods are well defined, AsyncGenerator extends AsyncIteratorObject on 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 new AsyncIteratorObject type from ts 5.6 https://devblogs.microsoft.com/typescript/announcing-typescript-5-6/#iterator-helper-methods. it currently is identical to AsyncIterator but will have support for async iterator helpers

@SuperchupuDev SuperchupuDev force-pushed the chore/async-iterator branch from 42dde6d to fda3ebc Compare July 5, 2025 15:41
@SuperchupuDev SuperchupuDev changed the title refactor: return an AsyncIterator instead refactor: return an AsyncGenerator instead Jul 5, 2025
@SuperchupuDev SuperchupuDev force-pushed the chore/async-iterator branch 6 times, most recently from 2df260e to 08a7741 Compare July 7, 2025 01:20
@43081j 43081j force-pushed the iterator-madness branch from a15c95c to 8cc1f85 Compare July 10, 2025 06:50
@SuperchupuDev SuperchupuDev force-pushed the chore/async-iterator branch from 08a7741 to 447a10f Compare July 10, 2025 20:19
@SuperchupuDev SuperchupuDev force-pushed the chore/async-iterator branch from 447a10f to 4d8a61c Compare July 10, 2025 20:27
Comment thread __tests__/fdir.test.ts
const iterator = api.withIterator()[Symbol.asyncIterator]();
const results: string[] = [];
const iterator = api.withIterator();
const results: (string | void)[] = [];
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

this doesn't seem right, its going to end up an array of string | undefined i guess

what causes it to emit undefined?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

its because you should check the done property in real world

when you do, it narrows the void out

@43081j
Copy link
Copy Markdown
Owner

43081j commented Jul 11, 2025

will merge in, if there's any changes i see, ill just do them in my branch 👍

@43081j 43081j merged commit d04ed18 into 43081j:iterator-madness Jul 11, 2025
@SuperchupuDev SuperchupuDev deleted the chore/async-iterator branch July 11, 2025 11:07
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