utilitas 1989.8.83 → 1989.8.84
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/lib/utilitas.js +6 -8
- package/package.json +1 -1
package/lib/utilitas.js
CHANGED
|
@@ -13,8 +13,8 @@ RegExp.escape = RegExp.escape || ((str) => { //$& means the whole matched string
|
|
|
13
13
|
const invalidTime = 'Invalid time.';
|
|
14
14
|
|
|
15
15
|
const tryOpts = {
|
|
16
|
-
interval: 1000 * 1, maxTry: 10, log: false,
|
|
17
|
-
verify: async (err, res) => { return !err
|
|
16
|
+
interval: 1000 * 1, maxTry: 10, log: false, error: 'Operation failed.',
|
|
17
|
+
verify: async (err, res) => { return !err; },
|
|
18
18
|
};
|
|
19
19
|
|
|
20
20
|
const clone = (any) => {
|
|
@@ -585,16 +585,14 @@ const ignoreErrFunc = async (f, o) => {
|
|
|
585
585
|
const tryUntil = async (fnTry, options) => {
|
|
586
586
|
options = { ...tryOpts, ...options || {} };
|
|
587
587
|
let [curTry, result, err] = [0, null, null];
|
|
588
|
-
|
|
588
|
+
do {
|
|
589
589
|
try {
|
|
590
|
-
result = await fnTry();
|
|
591
|
-
err = null;
|
|
590
|
+
assert(await options.verify((err = null), (result = await fnTry())), options.error);
|
|
592
591
|
} catch (e) {
|
|
593
|
-
err = e;
|
|
594
|
-
options?.log && console.error(e);
|
|
592
|
+
(err = e) && options?.log && console.error(e);
|
|
595
593
|
await timeout(options.interval);
|
|
596
594
|
}
|
|
597
|
-
}
|
|
595
|
+
} while (++curTry < options.maxTry && err)
|
|
598
596
|
err && throwError(err, 500);
|
|
599
597
|
return result;
|
|
600
598
|
};
|