JSFiddle - React, Tailwind, and code Playground
JavaScript
function doSomethingAsynchronous(n, m) {
return $.Deferred(function(dfrd) {
setTimeout(function(){dfrd.resolve(n + (m||''));}, 1000);
}).promise();
}
function synchronousFn(n, m) {
return n + (m||'');
}
function getA(obj) { //asynchronous
// all of obj's properties are available here
return doSomethingAsynchronous('A').then(function(result) {
obj.a = result;
return obj;
});
}
function getB(obj) { //synchronous
// all of obj's properties are available here
obj.b = synchronousFn('B');
return obj;
}
function getC(obj) {//asynchronous
// all of obj's properties are available here
return doSomethingAsynchronous(obj.a, obj.b).then(function(result) {
obj.c = result;
return obj;
});
}
$.when({x:'X'}).then(getA).then(getB).then(getC).then(function(obj) {
console.dir(obj);
});