-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSynchronizer-1.0.0.js
42 lines (37 loc) · 1.04 KB
/
Synchronizer-1.0.0.js
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
/*!
* Synchronizer.js
* async synchronization class
* https://github.com/sebastien-f/synchronizer-js
* MIT License : https://github.com/sebastien-f/synchronizer-js/blob/master/LICENSE
* 90% of this is inspired by this article:
* http://forrst.com/posts/callWhenDone_a_simple_synchronized_callback_clo-zi1
*/
/* v1.0.0 */
var Synchronizer = (function () {
function Synchronizer(cb) {
this.counter = 0;
this.callback = cb || function () {
};
}
Synchronizer.prototype.add = function (amount) {
if (!amount) {
amount = 1;
}
this.counter += amount;
};
Synchronizer.prototype.done = function (amount) {
if (!amount) {
amount = 1;
}
var newCounter = this.counter - amount;
if (newCounter < 0) {
throw "counter is negative";
}
this.counter = newCounter;
if (this.counter == 0) {
this.callback();
}
};
return Synchronizer;
})();
//# sourceMappingURL=Synchronizer-1.0.0.js.map