Skip to content

Instantly share code, notes, and snippets.

@designeng
Created October 10, 2013 13:56
Show Gist options
  • Save designeng/6918783 to your computer and use it in GitHub Desktop.
Save designeng/6918783 to your computer and use it in GitHub Desktop.
cujo.js when, callbacks usage
sumInForeSeconds = (a, b, callback) ->
console.log "sumInFiveSeconds"
setTimeout(()=>
callback(a + b)
, 4000)
sumInFiveSeconds = (a, b, callback) ->
console.log "sumInFiveSeconds"
setTimeout(()=>
callback(a + b)
, 5000)
sumPromise5 = callbacks.call(sumInFiveSeconds, 5, 10)
sumPromise4 = callbacks.call(sumInForeSeconds, 20, 7)
# When - instead of "when" (coffee compilator falls)
When.join(sumPromise5, sumPromise4).then( (res)->
console.log "RESULT": res
, (err) ->
console.log "ERROR", err
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment