Skip to content

Instantly share code, notes, and snippets.

@shama
Created April 25, 2014 16:20
Show Gist options
  • Save shama/11295084 to your computer and use it in GitHub Desktop.
Save shama/11295084 to your computer and use it in GitHub Desktop.
Comparing async vs sync functions in node.js
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