JSFiddle - React, Tailwind, and code Playground
JavaScript
var Process1 = function(){
this.dfd = new $.Deferred();
this.process();
return this.dfd.promise();
}
Process1.prototype.process = function(){
// backend process 1 taking 1 sec
setTimeout(function(){
this.dfd.notify('process1 done');
this.dfd.resolve();
}.bind(this), 1000);
}
var Process2 = function(){
this.dfd = $.Deferred();
this.process();
return this.dfd.promise();
}
Process2.prototype.process = function(){
// backend process 2 taking 2 sec
setTimeout(function(){
this.dfd.notify('process2 done');
this.dfd.resolve();
}.bind(this), 2000);
}
$.when(new Process1(), new Process2())
.progress(function(msg){
document.write(msg, ', ');
})
.then(function(){
document.write('[all ok]');
})
.fail(function(){
document.write('[something went wrong]');
});