Deferred, without an ajax call

by GregWoods

JavaScript

var promises = [];

function doThreeThings() {
	promises = [];
	
    for (var n = 0; n < 3; n++) {
        promises.push(doOneThing(n));
    }
    

	jQuery.when.apply(jQuery, promises).always(function () {
		alert('all three done!');
	});    
}

function doOneThing(n) {
    alert('one done: ' + n);
    var dfd = jQuery.Deferred();
    return dfd;
}


doThreeThings();