Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

OK. I'll do:

  const result = await get()
  set(result)
But you do you.

Current node and console have top level await BTW.



That only works in an async function. The then example doesn't have that requirement. So the alternative shouldn't either.


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())


Sometimes you may need to handle a promise in a function that can't be made async.


If a function is inherently sync, then it shouldn't be using promises.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: