Skip to content

Instantly share code, notes, and snippets.

@bahtou
Created March 19, 2013 12:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bahtou/5195898 to your computer and use it in GitHub Desktop.
Save bahtou/5195898 to your computer and use it in GitHub Desktop.
Blocking and Non-Blocking I/O
//BLOCKING
var post = db.query('SELECT * FROM posts where id = 1');
// processing from this line onward cannot execute
// until the line above completes
doSomethingWithPost(post);
doSomethingElse();
//NON-BLOCKING
callback = function(post) {
// this will only execute when the db.query function returns.
doSomethingWithPost(post);
};
db.query('SELECT * FROM posts where id = 1', callback);
// this will execute independent of the returned status
// of the db.query call.
doSomethingElse();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment