CoffeeScript support generator now, but, I found only you use yield
keyword, then your function will be compiled to generator, here is my question, I use koa
to write my code, and some middleware I do not need async logic, so I don't need yield
, so, CoffeeScript think it is an normal function, but, koa
says: app.use() requires a generator function
, T^T, anyone have a solution? Thank You!
Use the force, Luke! ;)
I ported the example from the homepage to CoffeeScript, and simply made the last handler also accept a next
argument and yield
to it, despite that being totally unnecessary.
Turns it works just fine. Doing yield null
instead, however, does not work.
koa = require("koa")
app = koa()
# x-response-time
app.use (next) ->
start = new Date
yield next
ms = new Date - start
@set 'X-Response-Time', ms + 'ms'
# logger
app.use (next) ->
start = new Date
yield next
ms = new Date - start
console.log '%s %s - %s', this.method, this.url, ms
# response
app.use (next) ->
@body = "Hello World"
yield next
app.listen(3000)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments