Sync iterables and [[asyncIterator]]

Gus Caplan me at
Sun Aug 19 23:46:45 UTC 2018

If you use for-await syntax, the js implementation will internally use GetIterator[1] which will look for Symbol.asyncIterator and if it can't find it it will return an async wrapper around Symbol.iterator -Gus [1]: ---- On Sun, 19 Aug 2018 16:34:27 -0500 Herbert Vojčík <herby at> wrote ---- Hello! Lately, I created this in one project: export async function* zip (...iterables) { for (const iterators = => (each[Symbol.iterator] || each[Symbol.asyncIterator]).apply(each)); ;) { const all = await Promise.all( each => await; if (all.some(each => each.done)) break; yield => each.value); } } It was sync generator before, but once one of the entries became async generator, I changed the zip itself to be async. My question is to the pretty ugly const iterators = => (each[Symbol.iterator] || each[Symbol.asyncIterator]).apply(each)) Is there some more idiomatic way to find "any iterator; sync or async" / alternatively, could sync iterator return respective [[asyncIterator]] as well, just promisifying the result (as a sort of proto-proposal of sort)? Or is there some easy way to change sync iterable to async iterable, so I could change the other ones at call site? Thanks, Herby _______________________________________________ es-discuss mailing list es-discuss at
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <>

More information about the es-discuss mailing list