Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Does this work with async/await? #26

Closed
felixfbecker opened this issue Oct 3, 2015 · 4 comments
Closed

Does this work with async/await? #26

felixfbecker opened this issue Oct 3, 2015 · 4 comments

Comments

@felixfbecker
Copy link
Contributor

Koa supports async functions, which is very useful for route definitions if you want to fetch some stuff from a database etc. But you have to use await inside the function. Since this doesn't return a promise, I can't await it... Why don't you make it return a promise? People could still yield it inside generator function middleware as they are automatically wrapped with co.
Example:

router.get('/pictures/:id', async function (next) {
  let files = await glob(this.request.params.id + '.*')
  if (files.length === 0) {
    throw new HttpError(404)
  }
  await sendFile(this, PATH + '/' + files[0])
})
@jonathanong
Copy link
Member

PR welcomed!!!

@felixfbecker
Copy link
Contributor Author

Forked and didn't make any changes but tests fail

@jonathanong
Copy link
Member

are you on windows?

@jonathanong
Copy link
Member

oh you're the same person. lol. #32 let me know if this works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants