Created
April 25, 2014 16:20
-
-
Save shama/11295084 to your computer and use it in GitHub Desktop.
Comparing async vs sync functions in node.js
This file contains hidden or 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
function sync(callback) { | |
callback() | |
} | |
function async(callback) { | |
process.nextTick(function() { | |
callback() | |
}) | |
} | |
sync(function() { | |
console.log('calling sync') | |
}) | |
console.log('after sync') | |
console.log('------') | |
async(function() { | |
console.log('calling async') | |
}) | |
console.log('after async?') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment