00:01
<jschoi>
o7…It’s a person saluting.
00:01
<jschoi>
Also, I’m trying to figure out where it is specified that for await, when given a non-async iterable, performs await on each of the iterable’s items.
00:01
<jschoi>
In https://tc39.es/ecma262/#sec-runtime-semantics-forin-div-ofbodyevaluation-lhs-stmt-iterator-lhskind-labelset, step 6.b, when iteratorKind is async, then Await is called on nextResult itself. But I don’t see any place where Await is called on nextValue
00:12
<bakkot>
jschoi: I believe it's in AsyncFromSyncIteratorPrototype
00:12
<bakkot>
i will see if I can find it
00:13
<bakkot>
https://tc39.es/ecma262/multipage/control-abstraction-objects.html#sec-asyncfromsynciteratorcontinuation
00:15
<bakkot>
that is, the AsyncFromSyncIteratorPrototype wrapper doesn't return Promise.resolve({ value: innerValue, done: false }) directly, as you might expect; rather, it yields Promise.resolve(innerValue).then(unwrapped => ({ value: unwrapped, done: false }))
00:20
<bakkot>

incidentally, the fact that Await is not called on nextValue means that it's actually possible to cause the loop variable in a for await to hold a Promise if you construct the async iterator manually, though you should not do this:

let x = { [Symbol.asyncIterator](){ let first = true; return { next(){ if (first) { first = false; return { value: Promise.resolve(0), done: false }; } else return { done: true }; } } } };
for await (let a of x) console.log(a); // prints a Promise holding 0
01:32
<jschoi>
bakkot: Aha, thank you very much. This will help me very much.
02:23
<jschoi>
(Background for those curious: https://github.com/tc39/proposal-array-from-async/issues/9)