-
-
Notifications
You must be signed in to change notification settings - Fork 4k
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(Collector): add iterators and getters #9165
base: main
Are you sure you want to change the base?
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next_
and the new async iterators look quite similar, these could probably be abstracted, if it doesn't hurt readability too much 👀
This needs a rebase |
* @type {Promise} | ||
* @readonly | ||
*/ | ||
get nextCollecting() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel like we shouldn't have async getters. What about waitForCollect()
? Same for the other methods.
I also think that it'd be useful to accept an AbortSignal
so we can cancel and unregister the listeners earlier.
this.removeListener('collect', tick); | ||
this.removeListener('dispose', tick); | ||
this.removeListener('end', tick); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't removing the ignore
listener that's registering in line 394.
Also, regarding this description:
Technically you can achieve the helper iterators by filtering the main iterator: for await (const [type, value] of collector) {
if (type !== ...) continue;
} However, they would use more resources than the dedicated ones, as it registers 2 more events. And the next one can achieved with similar code. Praying to get async iterator helpers soon so we can do this 🙏🏼: const next = await collector.filter(([type]) => type === ...).next(); |
Please describe the changes this PR makes and why it should be merged:
This PR adds new iterators and getters that allow you use collectors without deep nesting.
Status and versioning classification: