Skip to content

Instantly share code, notes, and snippets.

@gnepud
Created September 2, 2011 12:58
Show Gist options
  • Save gnepud/1188541 to your computer and use it in GitHub Desktop.
Save gnepud/1188541 to your computer and use it in GitHub Desktop.
Difference of asynchronous and synchronous programming
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