How can I force use generator on Coffeescript 1.9?

PerterPon

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!

Chris W

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.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How can I use literate coffeescript for my Gruntfile

From Dev

Can I use Coffeescript and ERB in the same file and keep readable indentation?

From Dev

How can I use grunt-contrib-watch and grunt-contrib-coffee to compile CoffeeScript only as needed?

From Dev

How can I force Kendo Grid to use a numeric filter on a column

From Dev

How can I force the singular table name on Rails scaffold generator?

From Dev

How can i force Highcharts to use same symbols in Legend and Series?

From Dev

Can I use CoffeeScript to write my Electron (Atom Shell) application?

From Dev

How can I force IE to *not* use compatibility mode?

From Dev

How can I force UriBuilder to use https?

From Dev

How to change separator in CoffeeScript generator?

From Dev

How can I use CoffeeScript sourcemaps in error handling using NodeJS?

From Dev

How can I force okhttp to use http/2 for a request?

From Dev

How to force a variable to be local in coffeescript?

From Dev

How can I force the use of a specific binary when running a script

From Dev

Can I use Coffeescript and ERB in the same file and keep readable indentation?

From Dev

How can I force Kendo Grid to use a numeric filter on a column

From Dev

How force use "this" in coffeeScript?

From Dev

How can I unroll callbacks in Coffeescript?

From Dev

How can I force the use of a crossover cable instead of wireless?

From Dev

How can I force use generator on Coffeescript 1.9?

From Dev

How can I force the X server to use my nvidia card?

From Dev

How can I make this CoffeeScript object work?

From Dev

How can I force PlayonLinux to use Wine 4?

From Dev

How can I make a query force to use such an index?

From Dev

How can I force Matlab to use all cores of my laptop?

From Dev

how can I use coffeescript with jquery?

From Dev

How can I specify a variant for a coffeescript view?

From Dev

App Generator: How can I declare a variable for use in the entire generator?

From Dev

How can I use a passcode generator for authentication for remote logins?

Related Related

  1. 1

    How can I use literate coffeescript for my Gruntfile

  2. 2

    Can I use Coffeescript and ERB in the same file and keep readable indentation?

  3. 3

    How can I use grunt-contrib-watch and grunt-contrib-coffee to compile CoffeeScript only as needed?

  4. 4

    How can I force Kendo Grid to use a numeric filter on a column

  5. 5

    How can I force the singular table name on Rails scaffold generator?

  6. 6

    How can i force Highcharts to use same symbols in Legend and Series?

  7. 7

    Can I use CoffeeScript to write my Electron (Atom Shell) application?

  8. 8

    How can I force IE to *not* use compatibility mode?

  9. 9

    How can I force UriBuilder to use https?

  10. 10

    How to change separator in CoffeeScript generator?

  11. 11

    How can I use CoffeeScript sourcemaps in error handling using NodeJS?

  12. 12

    How can I force okhttp to use http/2 for a request?

  13. 13

    How to force a variable to be local in coffeescript?

  14. 14

    How can I force the use of a specific binary when running a script

  15. 15

    Can I use Coffeescript and ERB in the same file and keep readable indentation?

  16. 16

    How can I force Kendo Grid to use a numeric filter on a column

  17. 17

    How force use "this" in coffeeScript?

  18. 18

    How can I unroll callbacks in Coffeescript?

  19. 19

    How can I force the use of a crossover cable instead of wireless?

  20. 20

    How can I force use generator on Coffeescript 1.9?

  21. 21

    How can I force the X server to use my nvidia card?

  22. 22

    How can I make this CoffeeScript object work?

  23. 23

    How can I force PlayonLinux to use Wine 4?

  24. 24

    How can I make a query force to use such an index?

  25. 25

    How can I force Matlab to use all cores of my laptop?

  26. 26

    how can I use coffeescript with jquery?

  27. 27

    How can I specify a variant for a coffeescript view?

  28. 28

    App Generator: How can I declare a variable for use in the entire generator?

  29. 29

    How can I use a passcode generator for authentication for remote logins?

HotTag

Archive