Async without the need for promises

AsyncBatch = function(context) {

var items = [],

asycnCount = 0,

onComplete,

ctx = context || window;

this.add = function(fn, params) {

items.push({

fn: fn,

params: params

});

}

this.run = function(callback) {

onComplete = callback;

for (var i in items) {

items[i].fn.apply(this, items[i].params);

}

}

this.done = function() {

if ( ++asycnCount >= items.length ) {

onComplete();

}

}

}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store