Closed maunier closed 7 years ago
Because now the render.renderToString function return nothing, but its a async function, i need return response in its callback, it will lead to bug in koa. I have to wrap it to a function return promise to let it to work. Something like this:
function render(renderer) { let resolve; const promise = new Promise(r => resolve = r); renderer.renderToString(context, (err, html) => { resolve(html); }); return promise; } server.get('*', async ctx => { const res = await render(renderer); ctx.status = 200; ctx.body = res; })
Maybe the render.renderToString return a promise will be better ?
koa2:
server.get('*', async ctx => { const res = await renderer.renderToString(context); ctx.status = 200; ctx.body = res; })
Maybe you can use util.promisify.
util.promisify
I do like that, considering we have somehow similar API with Vue.nextTick where you can pass callback or you get a promise.
Vue.nextTick
What problem does this feature solve?
Because now the render.renderToString function return nothing, but its a async function, i need return response in its callback, it will lead to bug in koa. I have to wrap it to a function return promise to let it to work. Something like this:
Maybe the render.renderToString return a promise will be better ?
What does the proposed API look like?
koa2: