Skip to content

Instantly share code, notes, and snippets.

View Willwf's full-sized avatar
📌
Focusing

William Firmino Willwf

📌
Focusing
View GitHub Profile

How to use async/await without try/catch block

We can use something like this:

async function resolveToNumber () {
  const promise = Promise.resolve(1)
  const [error, result] = await to(promise)
  console.log(error, result) // [null, 1] -> Here we have the result, and error will be null
}