News for hackers. Stuff that matters.
Re:Ask HN: Why can't await be used from non-async functions? by gabes on Monday February 28, 2022 @01:03PM (#30502885)
This isn't _exactly_ true. JS will await on anything that is Promiselike (an object with a `then` function that accepts a callback). See the TS definition of Promiselike.
Re:Ask HN: Why can't await be used from non-async functions? by claytongulick on Monday February 28, 2022 @01:17PM (#30503051)
JS will await on literals too, it just immediately resolves to the value of the literal.

I use this all the time in async functions with code branches, some of which await and some return an immediate value.