4 ms·
Koa has been doing async for a while. It's basically connect with promises instead of callbacks: `app.use(async (ctx, next) => { await next(); });`
by kosinus 9y ago
Koa has been doing async for a while. It's basically connect with promises instead of callbacks: `app.use(async (ctx, next) => { await next(); });`
- mikermcneil 9y agoAs long as you're on Node >=v7.9, you can also use `await` in Sails, Koa, or any other tool that supports promises. There's some work we had to do to make it feel nicer, and we had to update docs and stuff, but for the most part it was pretty painless-- all thanks to the JavaScript engine. And `await` is so much easier and safer than callbacks in userland code! Really excited about Node.js in 2018, now that `await` is supported in the LTS release. Callback hell is finally dead. (Diff showing a refactor of an example app from traditional callbacks to async/await: https://github.com/mikermcneil/chatkin/pull/4/files https://github.com/mikermcneil/chatkin/pull/4/files)