For some reason, these two statements seem to have the same effect:
yield await promise yield promise
The first statement is actually compiled in yield yield __await(promise) in Javascript, which works as expected. I think the idea is that you should be able to return either an iteration element or a promise of the element, so await not really necessary
From my understanding of the async iterator spec, it should be used in cases where the iteration itself is asynchronous, in your case the iteration itself is not asynchronous, it is rather an asynchronous method that returns the interaction. I would go with:
async function renderAll(): Promise<Iterable<Promise<IBlob>>> { const canvases = await getCanvases(); return (function* () { for (const canvas of canvases) { yield new Promise<IBlob>((resolve, reject) => { canvas.toBlob(result => { if (result) resolve(result); else reject(); }); }); } })(); }
OR
async function renderAll4(): Promise<Iterable<Promise<IBlob>>> { return (await getCanvases()) .map(canvas => new Promise<IBlob>((resolve, reject) => { canvas.toBlob(result => { if (result) resolve(result); else reject(); }); }) ); }
source share