@certik/skynet 0.10.62 → 0.10.64
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/availability.js +8 -9
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
package/availability.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
async function wait(time) {
|
|
2
|
-
return new Promise(resolve => {
|
|
2
|
+
return new Promise((resolve) => {
|
|
3
3
|
setTimeout(resolve, time);
|
|
4
4
|
});
|
|
5
5
|
}
|
|
@@ -22,10 +22,7 @@ async function retry(times, verbose, func) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
async function exponentialRetry(
|
|
26
|
-
func,
|
|
27
|
-
{ maxRetry, initialDuration, growFactor, test, verbose }
|
|
28
|
-
) {
|
|
25
|
+
async function exponentialRetry(func, { maxRetry, initialDuration, growFactor, test, verbose }) {
|
|
29
26
|
let retries = maxRetry;
|
|
30
27
|
let duration = initialDuration || 5000;
|
|
31
28
|
let growFactorFinal = growFactor || 2;
|
|
@@ -37,9 +34,7 @@ async function exponentialRetry(
|
|
|
37
34
|
console.log("failed attempt result", result);
|
|
38
35
|
}
|
|
39
36
|
|
|
40
|
-
console.log(
|
|
41
|
-
`sleep for ${duration}s after failed attempt, remaining ${retries} attempts`
|
|
42
|
-
);
|
|
37
|
+
console.log(`sleep for ${duration}ms after failed attempt, remaining ${retries} attempts`);
|
|
43
38
|
retries = retries - 1;
|
|
44
39
|
|
|
45
40
|
await wait(duration);
|
|
@@ -48,11 +43,15 @@ async function exponentialRetry(
|
|
|
48
43
|
duration = duration * growFactorFinal;
|
|
49
44
|
}
|
|
50
45
|
|
|
46
|
+
if (verbose) {
|
|
47
|
+
console.log(`function to retry ends with status ${test(result)}, number of retries done: ${maxRetry - retries}}`);
|
|
48
|
+
}
|
|
49
|
+
|
|
51
50
|
return result;
|
|
52
51
|
}
|
|
53
52
|
|
|
54
53
|
module.exports = {
|
|
55
54
|
wait,
|
|
56
55
|
retry,
|
|
57
|
-
exponentialRetry
|
|
56
|
+
exponentialRetry,
|
|
58
57
|
};
|