MatAtBread / fast-async

605 stars 21 forks source link

async functions are omitted when called from a regular function #41

Closed tyrak closed 6 years ago

tyrak commented 6 years ago

I was experimenting with fast-async and babel and I got the following unexpected behavior: Suppose that you have the following input file:

async function dummy() {
    console.log("test");
}

// execute dummy in the background:
dummy();

If I transpile it with babel, the output is empty. When I change the last line to

dummy().then();

then everything works as expected.

I have configured babel with plugins: ["fast-async", {spec: true}] without any preset.

matAtWork commented 6 years ago

This works for me (check the link below).

If I had to guess the issue, I'd suggest your config for fast-async is missing/incorrect, and so it's falling back to the default, which is to use LazyThenables.

http://nodent.mailed.me.uk/#async%20function%20dummy()%20%7B%0A%09console.log(%22test%22)%3B%0A%7D%0A%0Adummy()%3B%0A~options~%7B%22mode%22%3A%22promises%22%2C%22promiseType%22%3A%22Zousan%22%2C%22noRuntime%22%3Atrue%2C%22es6target%22%3Afalse%2C%22wrapAwait%22%3Atrue%2C%22spec%22%3Atrue%7D

tyrak commented 6 years ago

I suspect that this is not the case. If I change the last line to dummy().then(); to force dummy to be included, I get the following:

function dummy() {
    return new Promise(function ($return, $error) {
        console.log("test");
        return $return();
    }.bind(this));
}

which doesn't look like as being lazy. Also, when I change the spec flag to false, I get different output, which makes me believe that fast-async does correctly find the configuration.

Finally, everything does seem to works correctly when I use nodent directly, the problem seems to be with babel+fast-async specifically.

matAtWork commented 6 years ago

Can you provide a .zip or .git repo with your base test case in? I'll see if I can spot what's going on.

tyrak commented 6 years ago

I investigated it futher and it turns out it was a bug in the previous version of rollup. It appears that it has been fixed now. Apologies for the spam.

matAtWork commented 6 years ago

NP. I'm glad you got it working