@babel/plugin-proposal-async-generator-functions

    In

    1. var _asyncGenerator = ...
    2. let agf = (() => {
    3. var _ref = _asyncGenerator.wrap(function* () {
    4. yield _asyncGenerator.await(1);
    5. yield 2;
    6. });
    7. return function agf() {
    8. };
    9. })();

    For await example

    1. async function* genAnswers() {
    2. var total = 0;
    3. for await (let val of stream) {
    4. total += await val;
    5. yield total;
    6. }
    7. }
    8. function forEach(ai, fn) {
    9. return ai.next().then(function(r) {
    10. if (!r.done) {
    11. fn(r);
    12. return forEach(ai, fn);
    13. }
    14. var output = 0;
    15. forEach(genAnswers(), function(val) {
    16. output += val.value;
    17. }).then(function() {
    18. console.log(output); // 42
    19. });

    Try it Out in the REPL

    1. {
    2. "plugins": ["@babel/plugin-proposal-async-generator-functions"]
    3. }
    1. require("@babel/core").transformSync("code", {
    2. plugins: ["@babel/plugin-proposal-async-generator-functions"],