Skip to content

Instantly share code, notes, and snippets.

@BayMinimum
Last active June 20, 2017 03:55
Show Gist options
  • Save BayMinimum/eaad5a45f9d32cd51955664b3ae22254 to your computer and use it in GitHub Desktop.
Save BayMinimum/eaad5a45f9d32cd51955664b3ae22254 to your computer and use it in GitHub Desktop.
function foo(param, callback){
setTimeout(()=>{
var res = some_blocking_function()
callback(res)
}, 0)
}
function foo2(param, callback){
if(param_is_wrong) callback("Wrong Parameter", -1)
else{
setTimeout(()=>{
var res = some_blocking_function()
callback(false, res)
}, 0)
}
}
foo(1, (res)=>{
console.log(res)
})
foo2(2, (err, res)=>{
if(err) console.log(err)
else console.log(res)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment