Skip to content

Instantly share code, notes, and snippets.

@nivertech
Created April 3, 2012 17:52
Show Gist options
  • Select an option

  • Save nivertech/2294140 to your computer and use it in GitHub Desktop.

Select an option

Save nivertech/2294140 to your computer and use it in GitHub Desktop.
CoffeeScript setTimeout problem

When you need to use scalar arguments after function arguments use one of the following approaches:

delayed_ping = (client) ->
  log "delayed_ping"
  setTimeout (c) -> 
               log 'ping'
               c.pingreq {}
             , KEEP_ALIVE_SEC*1000

or

delayed_ping = (client) ->
  log "delayed_ping"
  setTimeout ((c) -> log 'ping'; c.pingreq {}), KEEP_ALIVE_SEC*1000

or

handle_client = (c) -> 
                  log 'ping'
                  c.pingreq {}

delayed_ping = (client) ->
  log "delayed_ping"
  setTimeout handle_client, KEEP_ALIVE_SEC*1000
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment