MatAtBread / fast-async

605 stars 21 forks source link

await on literal value causes error #45

Closed otakustay closed 6 years ago

otakustay commented 6 years ago

In such code:

const getSearchCount = () => {
  return await {
    repoCount: 100,
    codeCount: 20
  };
};

fast-async will generate wrong code such as (copied from console):

function getSearchCount(keyword) {
  return new Promise(function ($return, $error) {
    return {
      repoCount: 100,
      codeCount: 20
    }.then($return, $error);
  }.$asyncbind(this));
}

which obviously leads to error (object does not have then method)

matAtWork commented 6 years ago

This is documented in the README for nodent (which underlies fast-async). Look at the section "await non-Promise" in https://github.com/MatAtBread/nodent#gotchas-and-es7-compatibility.

TLDR; you need to set wrapAwait: true option.

matAtWork commented 6 years ago

Incidentally, in your example, getSearchCount is not marked as async, which works in nodent, but not fast-async, since it is an extension of the specification supported by nodent.