This is with latest Bluebird (3.4.1) and Babel (6.11.4).
Many Babel users are using Bluebird.coroutine() in combination with transform-async-to-module-method to have Bluebird shim async/await.
Unfortunately, it's not a perfect shim. The following code:
async function foo() {
await syncFn();
console.log(3);
}
async function syncFn() {
return;
}
console.log(1);
foo();
console.log(2);
prints 1 3 2 with Bluebird.coroutine() and 1 2 3 with the default transform-async-to-generator method.
I've created this Phabricator ticket to track but it appears the issue lies here.
The above code transpiles to this, which I have cleaned up for readability:
var Bluebird = require('bluebird');
function foo() {
return Bluebird.coroutine(function* () {
yield syncFn();
console.log(3);
})();
}
function syncFn() {
return Bluebird.coroutine(function* () {
return;
})();
}
console.log(1);
foo();
console.log(2);
This is easily runnable in any Node runtime that supports generators:
$ node syncCoroutines.js
1
3
2
Is this intended behavior?
This is with latest Bluebird (3.4.1) and Babel (6.11.4).
Many Babel users are using
Bluebird.coroutine()in combination withtransform-async-to-module-methodto have Bluebird shimasync/await.Unfortunately, it's not a perfect shim. The following code:
prints
1 3 2withBluebird.coroutine()and1 2 3with the defaulttransform-async-to-generatormethod.I've created this Phabricator ticket to track but it appears the issue lies here.
The above code transpiles to this, which I have cleaned up for readability:
This is easily runnable in any Node runtime that supports generators:
Is this intended behavior?