-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfora.js
More file actions
38 lines (35 loc) · 769 Bytes
/
fora.js
File metadata and controls
38 lines (35 loc) · 769 Bytes
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
// for for event loop
function ForAsync(init, check, final, body) {
var self = this;
self.break = function () {
throw "forasync_break";
}
self.quit = function () {
self.brk = true;
}
self.brk = false;
init.call(self);
function loop(self) {
if (check.call(self) && !self.brk) {
try {
body.call(self, function (t) {
final.call(self);
setTimeout(loop, Number(t), self);
});
} catch (e) {
if (e === "forasync_break") {
self.brk = true;
} else {
throw e;
}
}
} else {
;
}
}
setTimeout(loop, 0, self);
}
function forAsync(init, check, final, body) {
return new ForAsync(init, check, final, body);
}
module.exports = forAsync;