lukeed / navaid

A navigation aid (aka, router) for the browser in 850 bytes~!
MIT License
778 stars 26 forks source link

How to write in Async/Await style? #32

Closed anonimusprogramus closed 4 years ago

anonimusprogramus commented 4 years ago

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.

anonimusprogramus commented 4 years ago

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

I'm closing this issue. Thanks.

lukeed commented 4 years ago

Ah, great! Glad you uncovered it.

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