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

[…asyncIterator] sugar for Array.fromAsync? #1301

Open
danielbayley opened this issue Jun 30, 2024 · 5 comments
Open

[…asyncIterator] sugar for Array.fromAsync? #1301

danielbayley opened this issue Jun 30, 2024 · 5 comments

Comments

@danielbayley
Copy link
Contributor

danielbayley commented Jun 30, 2024

What do we think about adding polyfills for iterator helpers—currently at stage 3 of the TC39 process—and their async equivalent, currently at stage 2?

@bbrk24
Copy link
Contributor

bbrk24 commented Jun 30, 2024

I wouldn't be against it, but aren't polyfills generally outside the scope of Civet?

@edemaine
Copy link
Collaborator

I agree that it seems out of the scope, given that this proposal seems to be a standard-library feature instead of a language feature. (Let me know if I misread.) So it seems you that you can just include an existing JS polyfill, and it'll work great with Civet.

@danielbayley
Copy link
Contributor Author

given that this proposal seems to be a standard-library feature instead of a language feature. So it seems you that you can just include an existing JS polyfill

Ah of course, makes sense. Do you happen to know of a good one?

I did wonder if Civet could possibly have some kind of [...asyncThing] sugar for Array.fromAsync

@danielbayley danielbayley changed the title Iterator helpers TC39 proposal […asyncIterator] sugar for Array.fromAsync? Jul 3, 2024
@edemaine
Copy link
Collaborator

edemaine commented Jul 3, 2024

The best polyfill I've found is https://github.com/MadProbe/iterator-helpers-polyfill
It's a bit out-of-date in the async side (see issue 15), but hopefully good enough for your purposes...

I'm not sure we want to redefine [...asyncThing] (though I see Array.fromAsync is backward-compatible in the sense that it supports regular iterators), but perhaps new notation like [...*asyncThing] could trigger this? Ideally we could also support [a, ...*b, ...c, ...*d] via something like [a, ...Array.fromAsync(b), ...c, ...Array.fromAsync(d)] (unless we can think up a more efficient compilation).

@bbrk24
Copy link
Contributor

bbrk24 commented Aug 27, 2024

Array::concat can handle multiple arguments, and is way faster than multiple spreads: JSBenchmark .concat is about 5x faster for me (Firefox on Windows). So, the compilation would be [a].concat(Array.fromAsync(b), c, Array.fromAsync(d)).

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

No branches or pull requests

3 participants