@xylabs/retry 4.0.2 → 4.0.4
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/neutral/index.d.ts +2 -13
- package/dist/neutral/index.d.ts.map +1 -0
- package/dist/neutral/index.mjs +12 -2
- package/dist/neutral/index.mjs.map +1 -1
- package/dist/neutral/retry.d.ts +11 -0
- package/dist/neutral/retry.d.ts.map +1 -0
- package/package.json +29 -29
- package/src/retry.ts +6 -2
- package/xy.config.ts +1 -3
package/dist/neutral/index.d.ts
CHANGED
|
@@ -1,13 +1,2 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
interface RetryConfig {
|
|
4
|
-
backoff?: number;
|
|
5
|
-
interval?: number;
|
|
6
|
-
retries?: number;
|
|
7
|
-
}
|
|
8
|
-
interface RetryConfigWithComplete<T = unknown> extends RetryConfig {
|
|
9
|
-
complete?: (result?: T) => boolean;
|
|
10
|
-
}
|
|
11
|
-
declare const retry: <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>) => Promise<T | undefined>;
|
|
12
|
-
|
|
13
|
-
export { type RetryConfig, type RetryConfigWithComplete, retry };
|
|
1
|
+
export * from './retry.ts';
|
|
2
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAA"}
|
package/dist/neutral/index.mjs
CHANGED
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// src/retry.ts
|
|
2
2
|
import { delay } from "@xylabs/delay";
|
|
3
3
|
var retry = async (func, config) => {
|
|
4
|
-
const {
|
|
4
|
+
const {
|
|
5
|
+
complete = (value) => value !== void 0,
|
|
6
|
+
retries = 0,
|
|
7
|
+
interval = 100,
|
|
8
|
+
backoff = 2
|
|
9
|
+
} = config ?? {};
|
|
5
10
|
const result = await func();
|
|
6
11
|
if (complete(result)) {
|
|
7
12
|
return result;
|
|
@@ -10,7 +15,12 @@ var retry = async (func, config) => {
|
|
|
10
15
|
return void 0;
|
|
11
16
|
}
|
|
12
17
|
await delay(interval);
|
|
13
|
-
return retry(func, {
|
|
18
|
+
return retry(func, {
|
|
19
|
+
backoff,
|
|
20
|
+
complete,
|
|
21
|
+
interval: interval * backoff,
|
|
22
|
+
retries: retries - 1
|
|
23
|
+
});
|
|
14
24
|
};
|
|
15
25
|
export {
|
|
16
26
|
retry
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/retry.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\nimport type { Promisable } from '@xylabs/promise'\n\nexport interface RetryConfig {\n backoff?: number\n interval?: number\n retries?: number\n}\n\nexport interface RetryConfigWithComplete<T = unknown> extends RetryConfig {\n complete?: (result?: T) => boolean\n}\n\nexport const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {\n const {
|
|
1
|
+
{"version":3,"sources":["../../src/retry.ts"],"sourcesContent":["import { delay } from '@xylabs/delay'\nimport type { Promisable } from '@xylabs/promise'\n\nexport interface RetryConfig {\n backoff?: number\n interval?: number\n retries?: number\n}\n\nexport interface RetryConfigWithComplete<T = unknown> extends RetryConfig {\n complete?: (result?: T) => boolean\n}\n\nexport const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {\n const {\n complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2,\n } = config ?? {}\n const result = await func()\n if (complete(result)) {\n return result\n }\n if (retries <= 0) {\n return undefined\n }\n await delay(interval)\n return retry(func, {\n backoff, complete, interval: interval * backoff, retries: retries - 1,\n })\n}\n"],"mappings":";AAAA,SAAS,aAAa;AAaf,IAAM,QAAQ,OAAoB,MAAuC,WAAgE;AAC9I,QAAM;AAAA,IACJ,WAAW,CAAC,UAAyB,UAAU;AAAA,IAAW,UAAU;AAAA,IAAG,WAAW;AAAA,IAAK,UAAU;AAAA,EACnG,IAAI,UAAU,CAAC;AACf,QAAM,SAAS,MAAM,KAAK;AAC1B,MAAI,SAAS,MAAM,GAAG;AACpB,WAAO;AAAA,EACT;AACA,MAAI,WAAW,GAAG;AAChB,WAAO;AAAA,EACT;AACA,QAAM,MAAM,QAAQ;AACpB,SAAO,MAAM,MAAM;AAAA,IACjB;AAAA,IAAS;AAAA,IAAU,UAAU,WAAW;AAAA,IAAS,SAAS,UAAU;AAAA,EACtE,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { Promisable } from '@xylabs/promise';
|
|
2
|
+
export interface RetryConfig {
|
|
3
|
+
backoff?: number;
|
|
4
|
+
interval?: number;
|
|
5
|
+
retries?: number;
|
|
6
|
+
}
|
|
7
|
+
export interface RetryConfigWithComplete<T = unknown> extends RetryConfig {
|
|
8
|
+
complete?: (result?: T) => boolean;
|
|
9
|
+
}
|
|
10
|
+
export declare const retry: <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>) => Promise<T | undefined>;
|
|
11
|
+
//# sourceMappingURL=retry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"retry.d.ts","sourceRoot":"","sources":["../../src/retry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAEjD,MAAM,WAAW,WAAW;IAC1B,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,OAAO,CAAC,EAAE,MAAM,CAAA;CACjB;AAED,MAAM,WAAW,uBAAuB,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,WAAW;IACvE,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,OAAO,CAAA;CACnC;AAED,eAAO,MAAM,KAAK,GAAU,CAAC,kBAAkB,MAAM,UAAU,CAAC,CAAC,GAAG,SAAS,CAAC,WAAW,uBAAuB,CAAC,CAAC,CAAC,KAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAe1I,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,16 +1,31 @@
|
|
|
1
1
|
{
|
|
2
|
-
"license": "LGPL-3.0-only",
|
|
3
2
|
"name": "@xylabs/retry",
|
|
3
|
+
"version": "4.0.4",
|
|
4
|
+
"description": "Base functionality used throughout XY Labs TypeScript/JavaScript libraries",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"delay",
|
|
7
|
+
"xylabs",
|
|
8
|
+
"utility",
|
|
9
|
+
"typescript",
|
|
10
|
+
"esm"
|
|
11
|
+
],
|
|
12
|
+
"homepage": "https://xylabs.com",
|
|
13
|
+
"bugs": {
|
|
14
|
+
"url": "git+https://github.com/xylabs/sdk-js/issues",
|
|
15
|
+
"email": "support@xylabs.com"
|
|
16
|
+
},
|
|
17
|
+
"repository": {
|
|
18
|
+
"type": "git",
|
|
19
|
+
"url": "git+https://github.com/xylabs/sdk-js.git"
|
|
20
|
+
},
|
|
21
|
+
"license": "LGPL-3.0-only",
|
|
4
22
|
"author": {
|
|
5
|
-
"email": "support@xylabs.com",
|
|
6
23
|
"name": "XY Labs Development Team",
|
|
7
|
-
"url": "https://xylabs.com"
|
|
8
|
-
},
|
|
9
|
-
"bugs": {
|
|
10
24
|
"email": "support@xylabs.com",
|
|
11
|
-
"url": "
|
|
25
|
+
"url": "https://xylabs.com"
|
|
12
26
|
},
|
|
13
|
-
"
|
|
27
|
+
"sideEffects": false,
|
|
28
|
+
"type": "module",
|
|
14
29
|
"exports": {
|
|
15
30
|
".": {
|
|
16
31
|
"types": "./dist/neutral/index.d.ts",
|
|
@@ -18,24 +33,16 @@
|
|
|
18
33
|
},
|
|
19
34
|
"./package.json": "./package.json"
|
|
20
35
|
},
|
|
21
|
-
"types": "./dist/neutral/index.d.ts",
|
|
22
36
|
"module": "./dist/neutral/index.mjs",
|
|
23
|
-
"
|
|
24
|
-
"keywords": [
|
|
25
|
-
"delay",
|
|
26
|
-
"xylabs",
|
|
27
|
-
"utility",
|
|
28
|
-
"typescript",
|
|
29
|
-
"esm"
|
|
30
|
-
],
|
|
37
|
+
"types": "./dist/neutral/index.d.ts",
|
|
31
38
|
"dependencies": {
|
|
32
|
-
"@xylabs/delay": "^4.0.
|
|
33
|
-
"@xylabs/promise": "^4.0.
|
|
39
|
+
"@xylabs/delay": "^4.0.4",
|
|
40
|
+
"@xylabs/promise": "^4.0.4"
|
|
34
41
|
},
|
|
35
42
|
"devDependencies": {
|
|
36
|
-
"@xylabs/ts-scripts-yarn3": "^4.0.
|
|
37
|
-
"@xylabs/tsconfig": "^4.0.
|
|
38
|
-
"@xylabs/tsconfig-dom": "^4.0.
|
|
43
|
+
"@xylabs/ts-scripts-yarn3": "^4.0.7",
|
|
44
|
+
"@xylabs/tsconfig": "^4.0.7",
|
|
45
|
+
"@xylabs/tsconfig-dom": "^4.0.7",
|
|
39
46
|
"typescript": "^5.5.4"
|
|
40
47
|
},
|
|
41
48
|
"engines": {
|
|
@@ -43,12 +50,5 @@
|
|
|
43
50
|
},
|
|
44
51
|
"publishConfig": {
|
|
45
52
|
"access": "public"
|
|
46
|
-
}
|
|
47
|
-
"repository": {
|
|
48
|
-
"type": "git",
|
|
49
|
-
"url": "git+https://github.com/xylabs/sdk-js.git"
|
|
50
|
-
},
|
|
51
|
-
"sideEffects": false,
|
|
52
|
-
"version": "4.0.2",
|
|
53
|
-
"type": "module"
|
|
53
|
+
}
|
|
54
54
|
}
|
package/src/retry.ts
CHANGED
|
@@ -12,7 +12,9 @@ export interface RetryConfigWithComplete<T = unknown> extends RetryConfig {
|
|
|
12
12
|
}
|
|
13
13
|
|
|
14
14
|
export const retry = async <T = unknown>(func: () => Promisable<T | undefined>, config?: RetryConfigWithComplete<T>): Promise<T | undefined> => {
|
|
15
|
-
const {
|
|
15
|
+
const {
|
|
16
|
+
complete = (value: T | undefined) => value !== undefined, retries = 0, interval = 100, backoff = 2,
|
|
17
|
+
} = config ?? {}
|
|
16
18
|
const result = await func()
|
|
17
19
|
if (complete(result)) {
|
|
18
20
|
return result
|
|
@@ -21,5 +23,7 @@ export const retry = async <T = unknown>(func: () => Promisable<T | undefined>,
|
|
|
21
23
|
return undefined
|
|
22
24
|
}
|
|
23
25
|
await delay(interval)
|
|
24
|
-
return retry(func, {
|
|
26
|
+
return retry(func, {
|
|
27
|
+
backoff, complete, interval: interval * backoff, retries: retries - 1,
|
|
28
|
+
})
|
|
25
29
|
}
|