I would like to write a function that takes a callback and calls it after the function is done.
This is easy:
var callback = function (ref) {
var i = 1337;
while (i--) {
console.log(ref, 'callback');
}
};
var someFoo = function (ref, callback) {
console.log(ref, 'self');
callback(ref);
}
someFoo('one', callback); // 1
someFoo('two', callback); // 2
But here I'm facing this problem: First the someFoo
call blocks until the allback is finished. That means this code is equivalent to this (which blocks until each function is finished):
someFoo('one');
callback('one');
someFoo('two');
callback('two');
Now the question: How to make the callback call asynchronous?