@takeshape/util 10.8.2 → 10.10.6

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/dist/delay.d.ts CHANGED
@@ -1,7 +1,8 @@
1
- export declare const delay: <T>(timeout: number, value?: T | undefined) => Promise<T>;
1
+ export declare function delay<T>(timeout: number, value?: T): Promise<T>;
2
2
  export type Attempt = {
3
3
  num: number;
4
4
  lastDelay: number;
5
5
  };
6
6
  export declare function backoff(baseDelay: number, maxDelay: number, attempt?: Attempt): Promise<Attempt>;
7
+ export declare function randomDelay<T>(minimum: number, maximum: number, value?: T): Promise<T>;
7
8
  //# sourceMappingURL=delay.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../src/delay.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,KAAK,eAAsB,MAAM,sCAG1C,CAAC;AAEL,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AASF,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAAgC,GACxC,OAAO,CAAC,OAAO,CAAC,CAOlB"}
1
+ {"version":3,"file":"delay.d.ts","sourceRoot":"","sources":["../../src/delay.ts"],"names":[],"mappings":"AAAA,wBAAsB,KAAK,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAIrE;AAED,MAAM,MAAM,OAAO,GAAG;IACpB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AASF,wBAAsB,OAAO,CAC3B,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,MAAM,EAChB,OAAO,GAAE,OAAgC,GACxC,OAAO,CAAC,OAAO,CAAC,CAOlB;AAED,wBAAsB,WAAW,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAE5F"}
package/dist/delay.js CHANGED
@@ -4,11 +4,13 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.backoff = backoff;
7
- exports.delay = void 0;
8
- const delay = async (timeout, value) => new Promise(resolve => {
9
- setTimeout(resolve, timeout, value);
10
- });
11
7
  exports.delay = delay;
8
+ exports.randomDelay = randomDelay;
9
+ async function delay(timeout, value) {
10
+ return new Promise(resolve => {
11
+ setTimeout(resolve, timeout, value);
12
+ });
13
+ }
12
14
  function randomInt(minimum, maximum) {
13
15
  const co = Math.random() * (maximum - minimum + 1);
14
16
  return Math.floor(co + minimum);
@@ -26,4 +28,7 @@ async function backoff(baseDelay, maxDelay, attempt = {
26
28
  num: attempt.num + 1,
27
29
  lastDelay: msec
28
30
  };
31
+ }
32
+ async function randomDelay(minimum, maximum, value) {
33
+ return delay(randomInt(minimum, maximum), value);
29
34
  }
package/es/delay.js CHANGED
@@ -1,6 +1,8 @@
1
- export const delay = async (timeout, value) => new Promise(resolve => {
2
- setTimeout(resolve, timeout, value);
3
- });
1
+ export async function delay(timeout, value) {
2
+ return new Promise(resolve => {
3
+ setTimeout(resolve, timeout, value);
4
+ });
5
+ }
4
6
  function randomInt(minimum, maximum) {
5
7
  const co = Math.random() * (maximum - minimum + 1);
6
8
  return Math.floor(co + minimum);
@@ -18,4 +20,7 @@ export async function backoff(baseDelay, maxDelay, attempt = {
18
20
  num: attempt.num + 1,
19
21
  lastDelay: msec
20
22
  };
23
+ }
24
+ export async function randomDelay(minimum, maximum, value) {
25
+ return delay(randomInt(minimum, maximum), value);
21
26
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@takeshape/util",
3
- "version": "10.8.2",
3
+ "version": "10.10.6",
4
4
  "description": "Shared utilities",
5
5
  "homepage": "https://www.takeshape.io",
6
6
  "repository": {
@@ -33,7 +33,7 @@
33
33
  "shortid": "^2.2.16",
34
34
  "tiny-invariant": "^1.2.0",
35
35
  "url-parse": "^1.5.3",
36
- "@takeshape/routing": "10.8.2"
36
+ "@takeshape/routing": "10.10.6"
37
37
  },
38
38
  "devDependencies": {
39
39
  "@types/classnames": "^2.2.9",
@@ -46,7 +46,7 @@
46
46
  "@types/prismjs": "^1.16.2",
47
47
  "@types/shortid": "^0.0.29",
48
48
  "stripe": "13.8.0",
49
- "@takeshape/typescript-jest-junit-reporter": "10.8.2"
49
+ "@takeshape/typescript-jest-junit-reporter": "10.10.6"
50
50
  },
51
51
  "engines": {
52
52
  "node": ">=18"