The following code uses an async iterator to deliver "frames".
But this approach leaves an unused variable (_).
If this is a valid approach, why was while await (a hypothetical feature) not added when for await...of was?
while await would enable the omission of this ignored variable.
const raf = () => new Promise(resolve => requestAnimationFrame(resolve))
const frames = {
async *[Symbol.asyncIterator]() {
while (true) yield raf()
}
}
function createGameLoop(store) {
async function start() {
for await (let _ of frames)
render(store)
}
return { start }
}
while awaitnot added" I can't seem to find a proposal for this. If there is a proposal, it will be likely find why there - it might still be in progress, or rejected with a reason. If there isn't a proposal...well, there you go - it's why it wasn't added.while await(while awaitis a purely hypothetical feature BTW).