regenerator icon indicating copy to clipboard operation
regenerator copied to clipboard

Async functions fail because babel doesn't awrap result

Open sheerun opened this issue 9 years ago • 2 comments
trafficstars

Hey,

So in your source you check for AwaitArgument that can be created only by awrap function, but it turns out newest babel with default setup doesn't wrap result of async function with awrap what results in dropped promises.

Here is repository that reproduces the problem. Please notice result of async function isn't wrapped.

Any help to resolve this issue? What should I change?

sheerun avatar Jun 08 '16 00:06 sheerun

I believe you should be using babel-plugin-transform-regenerator instead of babel-plugin-transform-async-to-generator, but I agree this is something we should fix in the default setup.

benjamn avatar Jun 08 '16 00:06 benjamn

Actually it seems the issue is with download package. The code works when using dummy function like:

function download() {
  return new Promise((resolve, reject) => {
    setTimeout(function () {
      resolve('Hello world');
    }, 5000);
  });
}

Aside, any reason why babel doesn't wrap the result? I found a blogpost from June last year that shows babel used to do it, but it doesn't anymore when given the same code. How this code is relevant anymore then?

sheerun avatar Jun 08 '16 01:06 sheerun