lukeed/navaid

How to write in Async/Await style?

Closed this issue · 2 comments

Hi Luke, here's an example.

function fetchPromise() {
  httpie.get('someApi').then(res => console.log(res.data))
}

async function fetchAsync() {
  const res = await httpie.get('someApi')
  console.log(res.data)
}

let router = navaid()
router.on('/', () => fetchPromise())
router.listen()

fetchPromise() works, but fetchAsync() failed.

Thank you.

I just found the issue, it's babel-related. Here's the solution that worked for me.

I'm closing this issue. Thanks.

Ah, great! Glad you uncovered it.

Was going to say – those are semantically equivalent, it's just a difference in syntax