News for hackers. Stuff that matters.
Re:A Modern JavaScript Tutorial by postalrat on Wednesday December 09, 2020 @10:25AM (#25359432)
That only works in an async function. The then example doesn't have that requirement. So the alternative shouldn't either.
Re:A Modern JavaScript Tutorial by nailer on Wednesday December 09, 2020 @01:36PM (#25362136)
Yes, your example isn't complaining about then() being clearer than await (because it isn't) but rather complaining that top level await isn't everywhere yet.

In other words, your complaints have disappeared in node, and will soon in browsers: https://github.com/tc39/proposal-top-level-await

So yes:

    set(await get())
Re:A Modern JavaScript Tutorial by postalrat on Friday December 11, 2020 @12:08PM (#25387998)
Sometimes you may need to handle a promise in a function that can't be made async.
Re:A Modern JavaScript Tutorial by nailer on Friday December 11, 2020 @05:03PM (#25391863)
If a function is inherently sync, then it shouldn't be using promises.