ES6 generators: transforming callbacks to iterators

后端 未结 3 804
刺人心
刺人心 2020-12-19 05:04

I\'m experimenting with ES6 generators with the help of babel, and I have trouble understand how (or if!) I can effectively use callback based async function to output an it

3条回答
  •  青春惊慌失措
    2020-12-19 05:47

    Is there a way to get the intended behaviour using standard and current features

    Yes, use promises and generators. Many promise libraries, and some standalone ones, feature the use of generator "coroutines".

    But notice that you cannot mix iteration with asynchrony, you can use generators for either only. Your example seems to confuse them a bit - it looks like you expect that for ( {url, data} of downloadUrls(urls) ) { loop to work synchronously, which cannot work.

    do I have to wait for async/await?

    No, you don't have to wait, Babel already supports them!

提交回复
热议问题