MatAtBread / fast-async

605 stars 21 forks source link

Cannot await non-Promises. #59

Closed AndrewSouthpaw closed 5 years ago

AndrewSouthpaw commented 5 years ago

Using Babel 6, it appears right now that I cannot await any non-Promise value. E.g.

(async () => { await 1 })()

throws Uncaught (in promise) TypeError: 1.then is not a function. Is this by design, or is there something wrong with my setup?

AndrewSouthpaw commented 5 years ago

Well, it's at least nothing wrong with my setup. I tried doing it in the fast-async test file, and it had the same error.

Is there a reason we can't await non Promises? At least according to MDN you should be able to await any value.

AndreasCag commented 5 years ago

With babel 7 your snippet works fine 🤔

AndrewSouthpaw commented 5 years ago

Interesting. Worth noting that for me and the test scaffold it's using Babel 6.

matAtWork commented 5 years ago

This is documented in https://github.com/MatAtBread/nodent#differences-from-the-es7-specification

Nodent (used by fast-async) by default doesn't allow waiting on a non-promise as it's a significant performance hit. You can change the default to permit this using the fast-async spec or wrapAwait compiler options (see https://github.com/MatAtBread/fast-async#usage).

fast-async@7 sets this by default (you can unset it if you wish), by popular demand.

AndrewSouthpaw commented 5 years ago

Ah, that explains it, I was unfamiliar with nodent. Thanks for explaining!