Skip to content

Bluebird.coroutine() is sometimes synchronous #1170

Description

@STRML

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions