How to use the asyncToGenerator transformer.
Transforms async functions to a generator that uses a helper. This is useful if
you don't want to use regenerator
or bluebird
.
require("babel").transform("code", { optional: ["asyncToGenerator"] });
$ babel --optional asyncToGenerator script.js
In
async function foo() {
await bar();
}
Out
var _asyncToGenerator = function (fn) {
...
};
var foo = _asyncToGenerator(function* () {
yield bar();
});