-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (40 loc) · 963 Bytes
/
index.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
const wait = (ms) => new Promise((r) => setTimeout(r, ms));
/**
* build up
* @param {number} limit
*/
module.exports = function awaitif(options = { limit: 10000 }) {
/**
* continue follow the process
*/
var _continue = false;
this.continue = async function () {
_continue = true;
};
/**
* This function puts it at the line that you do not want the compiler to cross before the condition is true
* @param {function} callback
*/
this.finally = async function (callback) {
var i = 0;
var stats = true;
const Interval = setInterval(async () => {
i++;
if (i >= options.limit && options.limit) {
clearInterval(Interval);
callback(new Error("limit exceeded"));
}
if (_continue) {
clearInterval(Interval);
stats = false;
return;
}
}, 1);
while (stats) {
await wait(1);
}
};
};
/**
* @Copyright 2022 Arth(https://github.com/4i8/)
*/