Created
September 2, 2011 12:58
-
-
Save gnepud/1188541 to your computer and use it in GitHub Desktop.
Difference of asynchronous and synchronous programming
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
Asynchronous programming | |
JavaScript: | |
var a = 'foo'; | |
//lots of code | |
setTimeout(function(){ //Beginning of code that should run AFTER the timeout | |
alert(a); | |
//lots more code | |
},5000); | |
alert('before foo'); | |
Synchronous programming | |
Ruby: | |
def foo | |
sleep(5) | |
yield | |
end | |
foo { puts 'foo'} | |
puts 'before foo' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment