Here a test code:
var dfd_1 = $.Deferred(),
dfd_2 = $.Deferred(),
dfd_3 = $.Deferred();
function test(content, waitTime, dfd) {
console.log(content + ' begin');
setTimeout(function() {
console.log(content + ' end');
dfd.resolve();
}, waitTime);
return dfd.promise();
}
$.when(test('first', 2000, dfd_1), test('second', 4000, dfd_2), test('third', 6000, dfd_3))
.then(function() {
console.log('all done');
});
The result from console is:
first begin
second begin
third begin
first end
second end
third end
all done
3 function starts and after step by step ends But i need result like this (start end, start end...):
first begin
first end
second begin
second end
third begin
third end
all done
How to make $.Deferred work step by step? help me please with solution