Is there a better way to work with promises and callback?
#Is there a better way to work with promises and callback?
var result = doSomething();
var param = (result[x]) ? 'foo' : 'bar';
var otherResult = doSomethingElse(param);
var saveResult = saveSomething(otherResult);
return json(saveResult);
doSomething( function(err, result){
var param = (result[x]) ? 'foo' : 'bar';
doSomethingElse(param, function(err, otherResult){
saveSomething(otherResult, function (err, saveResult){
return json(saveResult);
});
});
});
###asynchronous programming promises pseudo example:
doSomething().then(function(result){
var param = (result[x]) ? 'foo' : 'bar';
doSomethingElse(param).then(function(otherResult){
saveSomething(otherResult).then(function(saveResult){
return json(saveResult);
}, function(error){
});
}, function(error){
});
}, function(error){
});