Skip to content

Instantly share code, notes, and snippets.

@mbains
Created August 13, 2012 15:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mbains/3342084 to your computer and use it in GitHub Desktop.
Save mbains/3342084 to your computer and use it in GitHub Desktop.
ending async callback hell with IcedCoffeeScript
#Simple example shows using await and defer of IcedCoffeeScript with setTimeout
#The calls within a code block are forced to wait until the previous defer action is completed.
#Program output:
# 1 going to sleep
# 2 going to sleep
# 2 done sleeping
# 1 done sleeping
test1 = ()->
console.log "1 going to sleep"
await setTimeout defer(dummy), 5000
console.log "1 done sleeping"
test2 = ()->
console.log "2 going to sleep"
await setTimeout defer(dummy), 3000
console.log "2 done sleeping"
test1()
test2()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment