@chriscdn/promise-retry 2.0.2 → 2.0.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/README.md +3 -3
- package/{dist/cjs → lib}/index.d.ts +7 -7
- package/lib/promise-retry.cjs +2 -0
- package/lib/promise-retry.cjs.map +1 -0
- package/lib/promise-retry.modern.js +2 -0
- package/lib/promise-retry.modern.js.map +1 -0
- package/lib/promise-retry.module.js +2 -0
- package/lib/promise-retry.module.js.map +1 -0
- package/lib/promise-retry.umd.js +2 -0
- package/lib/promise-retry.umd.js.map +1 -0
- package/package.json +15 -5
- package/dist/cjs/index.js +0 -24
- package/dist/cjs/index.js.map +0 -1
- package/dist/mjs/index.d.ts +0 -7
- package/dist/mjs/index.js +0 -22
- package/dist/mjs/index.js.map +0 -1
- package/tsconfig-cjs.json +0 -7
- package/tsconfig-esm.json +0 -7
- package/tsconfig.json +0 -12
package/README.md
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# @chriscdn/promise-retry
|
|
2
2
|
|
|
3
|
-
Retry
|
|
3
|
+
Retry an asynchronous function until it resolves successfully or exceeds the maximum attempt count.
|
|
4
4
|
|
|
5
5
|
## Installing
|
|
6
6
|
|
|
7
7
|
Using npm:
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
|
|
10
|
+
npm install @chriscdn/promise-retry
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
Using yarn:
|
|
14
14
|
|
|
15
15
|
```bash
|
|
16
|
-
|
|
16
|
+
yarn add @chriscdn/promise-retry
|
|
17
17
|
```
|
|
18
18
|
|
|
19
19
|
## Example 1 - Promises
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
type Options = {
|
|
2
|
-
maxAttempts: number;
|
|
3
|
-
retryDelay: number;
|
|
4
|
-
onError: (err: any, attempt: number) => void;
|
|
5
|
-
};
|
|
6
|
-
declare function promiseRetry<T>(func: (attempt: number) => Promise<T>, options?: Partial<Options>, attempt?: number): Promise<T>;
|
|
7
|
-
export default promiseRetry;
|
|
1
|
+
type Options = {
|
|
2
|
+
maxAttempts: number;
|
|
3
|
+
retryDelay: number;
|
|
4
|
+
onError: (err: any, attempt: number) => void;
|
|
5
|
+
};
|
|
6
|
+
declare function promiseRetry<T>(func: (attempt: number) => Promise<T>, options?: Partial<Options>, attempt?: number): Promise<T>;
|
|
7
|
+
export default promiseRetry;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function r(){return r=Object.assign?Object.assign.bind():function(r){for(var t=1;t<arguments.length;t++){var n=arguments[t];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(r[e]=n[e])}return r},r.apply(this,arguments)}var t={maxAttempts:10,retryDelay:0,onError:function(r,t){}};module.exports=function n(e,o,i){void 0===o&&(o=t),void 0===i&&(i=1);var a=r({},t,o);return e(i).catch(function(r){if(a.onError(r,i),i<a.maxAttempts)return new Promise(function(r){setTimeout(function(){return r(n(e,o,i+1))},a.retryDelay)});throw r})};
|
|
2
|
+
//# sourceMappingURL=promise-retry.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise-retry.cjs","sources":["../src/index.ts"],"sourcesContent":["type Options = {\n maxAttempts: number;\n retryDelay: number;\n onError: (err: any, attempt: number) => void;\n};\n\nconst defaultOptions: Options = {\n maxAttempts: 10,\n retryDelay: 0,\n onError: (err: any, attempt: number) => {},\n};\n\nfunction promiseRetry<T>(\n func: (attempt: number) => Promise<T>,\n options: Partial<Options> = defaultOptions,\n attempt = 1\n): Promise<T> {\n const config = { ...defaultOptions, ...options };\n\n return func(attempt).catch((err: any) => {\n // For logging...\n config.onError(err, attempt);\n\n if (attempt < config.maxAttempts) {\n return new Promise((resolve) => {\n setTimeout(\n () => resolve(promiseRetry(func, options, attempt + 1)),\n config.retryDelay\n );\n });\n } else {\n throw err;\n }\n });\n}\n\nexport default promiseRetry;\n"],"names":["defaultOptions","maxAttempts","retryDelay","onError","err","attempt","promiseRetry","func","options","config","_extends","Promise","resolve","setTimeout"],"mappings":"oOAMA,IAAMA,EAA0B,CAC9BC,YAAa,GACbC,WAAY,EACZC,QAAS,SAACC,EAAUC,qBAGtB,SAASC,EACPC,EACAC,EACAH,QADAG,IAAAA,IAAAA,EAA4BR,QAC5BK,IAAAA,IAAAA,EAAU,GAEV,IAAMI,EAAMC,EAAA,CAAA,EAAQV,EAAmBQ,GAEvC,OAAOD,EAAKF,GAAc,MAAC,SAACD,GAI1B,GAFAK,EAAON,QAAQC,EAAKC,GAEhBA,EAAUI,EAAOR,YACnB,OAAO,IAAIU,QAAQ,SAACC,GAClBC,WACE,WAAM,OAAAD,EAAQN,EAAaC,EAAMC,EAASH,EAAU,GAAG,EACvDI,EAAOP,WAEX,GAEA,MAAME,CAEV,EACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function t(){return t=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var e=arguments[r];for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])}return t},t.apply(this,arguments)}const r={maxAttempts:10,retryDelay:0,onError:(t,r)=>{}};function e(n,o=r,a=1){const s=t({},r,o);return n(a).catch(t=>{if(s.onError(t,a),a<s.maxAttempts)return new Promise(t=>{setTimeout(()=>t(e(n,o,a+1)),s.retryDelay)});throw t})}export{e as default};
|
|
2
|
+
//# sourceMappingURL=promise-retry.modern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise-retry.modern.js","sources":["../src/index.ts"],"sourcesContent":["type Options = {\n maxAttempts: number;\n retryDelay: number;\n onError: (err: any, attempt: number) => void;\n};\n\nconst defaultOptions: Options = {\n maxAttempts: 10,\n retryDelay: 0,\n onError: (err: any, attempt: number) => {},\n};\n\nfunction promiseRetry<T>(\n func: (attempt: number) => Promise<T>,\n options: Partial<Options> = defaultOptions,\n attempt = 1\n): Promise<T> {\n const config = { ...defaultOptions, ...options };\n\n return func(attempt).catch((err: any) => {\n // For logging...\n config.onError(err, attempt);\n\n if (attempt < config.maxAttempts) {\n return new Promise((resolve) => {\n setTimeout(\n () => resolve(promiseRetry(func, options, attempt + 1)),\n config.retryDelay\n );\n });\n } else {\n throw err;\n }\n });\n}\n\nexport default promiseRetry;\n"],"names":["defaultOptions","maxAttempts","retryDelay","onError","err","attempt","promiseRetry","func","options","config","_extends","catch","Promise","resolve","setTimeout"],"mappings":"oOAMA,MAAMA,EAA0B,CAC9BC,YAAa,GACbC,WAAY,EACZC,QAASA,CAACC,EAAUC,KAAXF,GAGX,SAASG,EACPC,EACAC,EAA4BR,EAC5BK,EAAU,GAEV,MAAMI,EAAMC,EAAA,CAAA,EAAQV,EAAmBQ,GAEvC,OAAOD,EAAKF,GAASM,MAAOP,IAI1B,GAFAK,EAAON,QAAQC,EAAKC,GAEhBA,EAAUI,EAAOR,YACnB,OAAW,IAAAW,QAASC,IAClBC,WACE,IAAMD,EAAQP,EAAaC,EAAMC,EAASH,EAAU,IACpDI,EAAOP,WAEX,GAEA,MAAME,CACP,EAEL"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
function t(){return t=Object.assign?Object.assign.bind():function(t){for(var r=1;r<arguments.length;r++){var n=arguments[r];for(var e in n)Object.prototype.hasOwnProperty.call(n,e)&&(t[e]=n[e])}return t},t.apply(this,arguments)}var r={maxAttempts:10,retryDelay:0,onError:function(t,r){}};function n(e,o,a){void 0===o&&(o=r),void 0===a&&(a=1);var i=t({},r,o);return e(a).catch(function(t){if(i.onError(t,a),a<i.maxAttempts)return new Promise(function(t){setTimeout(function(){return t(n(e,o,a+1))},i.retryDelay)});throw t})}export{n as default};
|
|
2
|
+
//# sourceMappingURL=promise-retry.module.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise-retry.module.js","sources":["../src/index.ts"],"sourcesContent":["type Options = {\n maxAttempts: number;\n retryDelay: number;\n onError: (err: any, attempt: number) => void;\n};\n\nconst defaultOptions: Options = {\n maxAttempts: 10,\n retryDelay: 0,\n onError: (err: any, attempt: number) => {},\n};\n\nfunction promiseRetry<T>(\n func: (attempt: number) => Promise<T>,\n options: Partial<Options> = defaultOptions,\n attempt = 1\n): Promise<T> {\n const config = { ...defaultOptions, ...options };\n\n return func(attempt).catch((err: any) => {\n // For logging...\n config.onError(err, attempt);\n\n if (attempt < config.maxAttempts) {\n return new Promise((resolve) => {\n setTimeout(\n () => resolve(promiseRetry(func, options, attempt + 1)),\n config.retryDelay\n );\n });\n } else {\n throw err;\n }\n });\n}\n\nexport default promiseRetry;\n"],"names":["defaultOptions","maxAttempts","retryDelay","onError","err","attempt","promiseRetry","func","options","config","_extends","Promise","resolve","setTimeout"],"mappings":"oOAMA,IAAMA,EAA0B,CAC9BC,YAAa,GACbC,WAAY,EACZC,QAAS,SAACC,EAAUC,MAGtB,SAASC,EACPC,EACAC,EACAH,QADAG,IAAAA,IAAAA,EAA4BR,QAC5BK,IAAAA,IAAAA,EAAU,GAEV,IAAMI,EAAMC,EAAA,CAAA,EAAQV,EAAmBQ,GAEvC,OAAOD,EAAKF,GAAc,MAAC,SAACD,GAI1B,GAFAK,EAAON,QAAQC,EAAKC,GAEhBA,EAAUI,EAAOR,YACnB,OAAO,IAAIU,QAAQ,SAACC,GAClBC,WACE,WAAM,OAAAD,EAAQN,EAAaC,EAAMC,EAASH,EAAU,GAAG,EACvDI,EAAOP,WAEX,GAEA,MAAME,CAEV,EACF"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?module.exports=e():"function"==typeof define&&define.amd?define(e):(t||self).promiseRetry=e()}(this,function(){function t(){return t=Object.assign?Object.assign.bind():function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t},t.apply(this,arguments)}var e={maxAttempts:10,retryDelay:0,onError:function(t,e){}};return function n(r,o,i){void 0===o&&(o=e),void 0===i&&(i=1);var f=t({},e,o);return r(i).catch(function(t){if(f.onError(t,i),i<f.maxAttempts)return new Promise(function(t){setTimeout(function(){return t(n(r,o,i+1))},f.retryDelay)});throw t})}});
|
|
2
|
+
//# sourceMappingURL=promise-retry.umd.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"promise-retry.umd.js","sources":["../src/index.ts"],"sourcesContent":["type Options = {\n maxAttempts: number;\n retryDelay: number;\n onError: (err: any, attempt: number) => void;\n};\n\nconst defaultOptions: Options = {\n maxAttempts: 10,\n retryDelay: 0,\n onError: (err: any, attempt: number) => {},\n};\n\nfunction promiseRetry<T>(\n func: (attempt: number) => Promise<T>,\n options: Partial<Options> = defaultOptions,\n attempt = 1\n): Promise<T> {\n const config = { ...defaultOptions, ...options };\n\n return func(attempt).catch((err: any) => {\n // For logging...\n config.onError(err, attempt);\n\n if (attempt < config.maxAttempts) {\n return new Promise((resolve) => {\n setTimeout(\n () => resolve(promiseRetry(func, options, attempt + 1)),\n config.retryDelay\n );\n });\n } else {\n throw err;\n }\n });\n}\n\nexport default promiseRetry;\n"],"names":["defaultOptions","maxAttempts","retryDelay","onError","err","attempt","promiseRetry","func","options","config","_extends","Promise","resolve","setTimeout"],"mappings":"mcAMA,IAAMA,EAA0B,CAC9BC,YAAa,GACbC,WAAY,EACZC,QAAS,SAACC,EAAUC,aAGtB,SAASC,EACPC,EACAC,EACAH,QADAG,IAAAA,IAAAA,EAA4BR,QAC5BK,IAAAA,IAAAA,EAAU,GAEV,IAAMI,EAAMC,EAAA,CAAA,EAAQV,EAAmBQ,GAEvC,OAAOD,EAAKF,GAAc,MAAC,SAACD,GAI1B,GAFAK,EAAON,QAAQC,EAAKC,GAEhBA,EAAUI,EAAOR,YACnB,OAAO,IAAIU,QAAQ,SAACC,GAClBC,WACE,WAAM,OAAAD,EAAQN,EAAaC,EAAMC,EAASH,EAAU,GAAG,EACvDI,EAAOP,WAEX,GAEA,MAAME,CAEV,EACF"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@chriscdn/promise-retry",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.6",
|
|
4
4
|
"description": "Retry a function returning a rejected promise until it resolves.",
|
|
5
|
-
"main": "./dist/cjs/index.js",
|
|
6
|
-
"module": "./dist/mjs/index.js",
|
|
7
5
|
"repository": "https://github.com/chriscdn/promise-retry",
|
|
8
6
|
"author": "Christopher Meyer <chris@schwiiz.org>",
|
|
9
7
|
"license": "MIT",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"source": "./src/index.ts",
|
|
10
|
+
"main": "./lib/promise-retry.cjs",
|
|
11
|
+
"module": "./lib/promise-retry.module.js",
|
|
12
|
+
"unpkg": "./lib/promise-retry.umd.js",
|
|
13
|
+
"exports": {
|
|
14
|
+
"types": "./lib/index.d.ts",
|
|
15
|
+
"require": "./lib/promise-retry.cjs",
|
|
16
|
+
"default": "./lib/promise-retry.modern.js"
|
|
17
|
+
},
|
|
18
|
+
"types": "./lib/index.d.ts",
|
|
10
19
|
"scripts": {
|
|
11
|
-
"build": "rm -rf ./
|
|
20
|
+
"build": "rm -rf ./lib/ && microbundle",
|
|
21
|
+
"dev": "microbundle watch"
|
|
12
22
|
},
|
|
13
23
|
"devDependencies": {
|
|
14
|
-
"
|
|
24
|
+
"microbundle": "^0.15.1"
|
|
15
25
|
},
|
|
16
26
|
"keywords": [
|
|
17
27
|
"promise",
|
package/dist/cjs/index.js
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const defaultOptions = {
|
|
4
|
-
maxAttempts: 10,
|
|
5
|
-
retryDelay: 0,
|
|
6
|
-
onError: (err, attempt) => { },
|
|
7
|
-
};
|
|
8
|
-
function promiseRetry(func, options = defaultOptions, attempt = 1) {
|
|
9
|
-
const config = { ...defaultOptions, ...options };
|
|
10
|
-
return func(attempt).catch((err) => {
|
|
11
|
-
// For logging...
|
|
12
|
-
config.onError(err, attempt);
|
|
13
|
-
if (attempt < config.maxAttempts) {
|
|
14
|
-
return new Promise((resolve) => {
|
|
15
|
-
setTimeout(() => resolve(promiseRetry(func, options, attempt + 1)), config.retryDelay);
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
else {
|
|
19
|
-
throw err;
|
|
20
|
-
}
|
|
21
|
-
});
|
|
22
|
-
}
|
|
23
|
-
exports.default = promiseRetry;
|
|
24
|
-
//# sourceMappingURL=index.js.map
|
package/dist/cjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":";;AAMA,MAAM,cAAc,GAAY;IAC9B,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,CAAC;IACb,OAAO,EAAE,CAAC,GAAQ,EAAE,OAAe,EAAE,EAAE,GAAE,CAAC;CAC3C,CAAC;AAEF,SAAS,YAAY,CACnB,IAAqC,EACrC,UAA4B,cAAc,EAC1C,OAAO,GAAG,CAAC;IAEX,MAAM,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IAEjD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE;QACtC,iBAAiB;QACjB,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAE7B,IAAI,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE;YAChC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,UAAU,CACR,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,EACvD,MAAM,CAAC,UAAU,CAClB,CAAC;YACJ,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,MAAM,GAAG,CAAC;SACX;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,kBAAe,YAAY,CAAC"}
|
package/dist/mjs/index.d.ts
DELETED
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
type Options = {
|
|
2
|
-
maxAttempts: number;
|
|
3
|
-
retryDelay: number;
|
|
4
|
-
onError: (err: any, attempt: number) => void;
|
|
5
|
-
};
|
|
6
|
-
declare function promiseRetry<T>(func: (attempt: number) => Promise<T>, options?: Partial<Options>, attempt?: number): Promise<T>;
|
|
7
|
-
export default promiseRetry;
|
package/dist/mjs/index.js
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
const defaultOptions = {
|
|
2
|
-
maxAttempts: 10,
|
|
3
|
-
retryDelay: 0,
|
|
4
|
-
onError: (err, attempt) => { },
|
|
5
|
-
};
|
|
6
|
-
function promiseRetry(func, options = defaultOptions, attempt = 1) {
|
|
7
|
-
const config = { ...defaultOptions, ...options };
|
|
8
|
-
return func(attempt).catch((err) => {
|
|
9
|
-
// For logging...
|
|
10
|
-
config.onError(err, attempt);
|
|
11
|
-
if (attempt < config.maxAttempts) {
|
|
12
|
-
return new Promise((resolve) => {
|
|
13
|
-
setTimeout(() => resolve(promiseRetry(func, options, attempt + 1)), config.retryDelay);
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
throw err;
|
|
18
|
-
}
|
|
19
|
-
});
|
|
20
|
-
}
|
|
21
|
-
export default promiseRetry;
|
|
22
|
-
//# sourceMappingURL=index.js.map
|
package/dist/mjs/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAMA,MAAM,cAAc,GAAY;IAC9B,WAAW,EAAE,EAAE;IACf,UAAU,EAAE,CAAC;IACb,OAAO,EAAE,CAAC,GAAQ,EAAE,OAAe,EAAE,EAAE,GAAE,CAAC;CAC3C,CAAC;AAEF,SAAS,YAAY,CACnB,IAAqC,EACrC,UAA4B,cAAc,EAC1C,OAAO,GAAG,CAAC;IAEX,MAAM,MAAM,GAAG,EAAE,GAAG,cAAc,EAAE,GAAG,OAAO,EAAE,CAAC;IAEjD,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,GAAQ,EAAE,EAAE;QACtC,iBAAiB;QACjB,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;QAE7B,IAAI,OAAO,GAAG,MAAM,CAAC,WAAW,EAAE;YAChC,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,EAAE;gBAC7B,UAAU,CACR,GAAG,EAAE,CAAC,OAAO,CAAC,YAAY,CAAC,IAAI,EAAE,OAAO,EAAE,OAAO,GAAG,CAAC,CAAC,CAAC,EACvD,MAAM,CAAC,UAAU,CAClB,CAAC;YACJ,CAAC,CAAC,CAAC;SACJ;aAAM;YACL,MAAM,GAAG,CAAC;SACX;IACH,CAAC,CAAC,CAAC;AACL,CAAC;AAED,eAAe,YAAY,CAAC"}
|
package/tsconfig-cjs.json
DELETED
package/tsconfig-esm.json
DELETED
package/tsconfig.json
DELETED