Created
February 9, 2014 03:24
-
-
Save shgtkshruch/8893745 to your computer and use it in GitHub Desktop.
Async JavaScript
This file contains 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
$ -> | |
# use settimeout | |
console.log 0 | |
setTimeout -> | |
console.log 'hi, 1' | |
setTimeout -> | |
console.log 'hi, 2' | |
, 1000 | |
console.log 1 | |
, 1000 | |
# use jQuery deferred | |
sleep = (time) -> | |
d = new $.Deferred | |
setTimeout -> | |
d.resolve() | |
, time | |
d.promise() | |
console.log 0 | |
sleep 1000 | |
.then -> | |
console.log 1 | |
sleep 1000 | |
.then -> | |
console.log 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment