Created
August 13, 2012 15:49
-
-
Save mbains/3342084 to your computer and use it in GitHub Desktop.
ending async callback hell with IcedCoffeeScript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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