I currently trying to implement a working prototype for async generators on top of Traceur, and (at least) one issue has come up:
Consider the function that is given as an example, namely async function* getStockPrices(stockNames, nameServiceUrl). In the provided transcription into an asynchronous function, the code is full of checks if ($done) { this.return(); return; }. This is needed if we want the getStockPrices observable to return as soon as possible.
However, I wonder whether this is really what one wants: If I wrap several of the await expressions in getStockPrices in one async function, which is then called by getStockPrices there will be only one check whether I'm done or not, but not one for every await in the wrapping function. Thus we would lose transparency here (between wrapped and non-wrapped code).
Doesn't it make more sense to test for stopping just before the next yield that is going to happen?
I currently trying to implement a working prototype for async generators on top of Traceur, and (at least) one issue has come up:
Consider the function that is given as an example, namely
async function* getStockPrices(stockNames, nameServiceUrl). In the provided transcription into an asynchronous function, the code is full of checksif ($done) { this.return(); return; }. This is needed if we want thegetStockPricesobservable to return as soon as possible.However, I wonder whether this is really what one wants: If I wrap several of the await expressions in
getStockPricesin one async function, which is then called bygetStockPricesthere will be only one check whether I'm done or not, but not one for every await in the wrapping function. Thus we would lose transparency here (between wrapped and non-wrapped code).Doesn't it make more sense to test for stopping just before the next
yieldthat is going to happen?