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.
Files changed (2) hide show
  1. package/lib/utilitas.js +6 -8
  2. 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 && res; },
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
- while (curTry++ < options.maxTry && !(await options.verify(err, result))) {
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
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "utilitas",
3
3
  "description": "Just another common utility for Node.js.",
4
- "version": "1989.8.83",
4
+ "version": "1989.8.84",
5
5
  "private": false,
6
6
  "homepage": "https://github.com/Leask/utilitas",
7
7
  "main": "index.js",