Koa2フレームワークNodejs 7とネイティブの async/await 関数を使用しています。koa-art-templateそして、約束が解決された後、結果のテンプレート(モジュール)をレンダリングしようとしています。
const app = new koa()
const searcher = require('./src/searcher')
app.use(async (ctx) => {
const params = ctx.request.query
if (ctx.request.path === '/') {
searcher.find(params).then((items) => {
await ctx.render('main', { items })
})
}
})
モジュールごとにアイテムを取得するのを待ちたいのですsearcherが、Koa でエラーが発生します
await ctx.render('main', { items })
^^^
SyntaxError: Unexpected identifier
await for を設定するsearcher.find(params).then(...)と、アプリケーションは機能しますが、アイテムを待ちません。