Skip to content

Instantly share code, notes, and snippets.

@maleck13
Created October 7, 2015 20:28
Show Gist options
  • Save maleck13/b285982e94e15264d40d to your computer and use it in GitHub Desktop.
Save maleck13/b285982e94e15264d40d to your computer and use it in GitHub Desktop.
code question
function remoteMathService(cb){
var one;
var two;
callOneService(function (err,num){
one = num;
});
callTwoService(function (err, num){
two = num;
});
return cb(undefined,one + two);
}
function callOneService(cb){
setTimeout(function (){
return cb(undefined,1);
},1000);
}
function callTwoService(cb){
setTimeout(function (){
return cb(undefined,2);
},1500);
}
remoteMathService(function (err, answer){
if(err) console.log("error ",err);
if(answer !== 3){
console.log("wrong answer",answer);
}else{
console.log("correct");
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment