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

}

}

}

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Jesse Chung
Jesse Chung

Written by Jesse Chung

0 Followers

Software Engineer of 3 years

No responses yet

Write a response