-
Notifications
You must be signed in to change notification settings - Fork 16
Labels
questionFurther information is requestedFurther information is requested
Description
Consider this async iterable:
const it = {
[Symbol.asyncIterator]() {
return {
async next() {
if (i > 2) return { done: true };
i++;
return { value: Promise.resolve(i), done: false }
}
}
}
}Unless I'm reading the spec wrong, await Array.fromAsync(it) returns [Promise.resolve(1), Promise.resolve(2), Promise.resolve(3)] while await Array.fromAsync(it, x => x) returns [1, 2, 3].
Currently, when using Array.from, x => x is the "default mapper function" (even if it's not specified as such): Array.from(something) is always equivalent to Array.from(something, x => x). However, there is no "default function" that can be passed to Array.fromAsync.
If we changed Array.fromAsync(something) to await the next.value values, await Array.fromAsync(it) would always return the same result as await Array.fromAsync(it, x => x). In practice, it means making it behave like
const arr = [];
for await (const nextValue of it) arr.push(await nextValue);binury
Metadata
Metadata
Assignees
Labels
questionFurther information is requestedFurther information is requested