Created
March 19, 2013 12:58
-
-
Save bahtou/5195898 to your computer and use it in GitHub Desktop.
Blocking and Non-Blocking I/O
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
//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