main.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
"use strict";

function asyncSqrt(value, callback) {
    console.log('START execution with value =', value);
    setTimeout(function() {
        callback(value, value * value);
    }, 0 | Math.random() * 100);
}

var max = 10;
var cnt = 0;
asyncSqrt(cnt, function callback(value, result) {
    console.log('END execution with value =', value, 'and result =', result);
    if (++cnt === max) {
        console.log('COMPLETED');
    } else {
        asyncSqrt(cnt, callback);
    }
});
Native Browser JavaScript