-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
45 lines (40 loc) · 1.03 KB
/
test.js
File metadata and controls
45 lines (40 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Created by Dmitry on 24.05.15.
*/
function MyAsync(finalCallback) {
this.finalCallback = finalCallback;
this.result = [];
this.counter = 0;
}
MyAsync.prototype = {
"add" : function (callback) {
var that = this;
this.counter ++;
return function () {
that.result[that.counter - 1] = callback.apply(this, arguments);
that.check();
};
},
"check" : function () {
var that = this;
this.counter --;
if (this.counter == 0)
process.nextTick(function () {
that.finalCallback.call(that, that.result);
});
}
};
var my_async = new MyAsync(
function (result) {
});
//console.log("begin");
//setTimeout(test.add(function () {
// console.log("2000ms"); return "2000ms"; }), 2000);
//
//setTimeout(test.add(function () {
// console.log("1500ms"); return "1500ms"; }), 1500);
//
//setTimeout(test.add(function () {
// console.log("1000ms"); return "1000ms"; }), 1000);
//
//console.log("end");