Async without the need for promises

Jesse Chung
Apr 8, 2022

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();

}

}

}

--

--