@daimo/pay-common 1.19.6 → 1.19.7
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/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/index.ts +0 -1
- package/src/retryBackoff.ts +0 -30
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
|
@@ -20,7 +20,6 @@ __exportStar(require("./daimoPay"), exports);
|
|
|
20
20
|
__exportStar(require("./debug"), exports);
|
|
21
21
|
__exportStar(require("./format"), exports);
|
|
22
22
|
__exportStar(require("./primitiveTypes"), exports);
|
|
23
|
-
__exportStar(require("./retryBackoff"), exports);
|
|
24
23
|
__exportStar(require("./token"), exports);
|
|
25
24
|
__exportStar(require("./try"), exports);
|
|
26
25
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,2CAAyB;AACzB,0CAAwB;AACxB,6CAA2B;AAC3B,0CAAwB;AACxB,2CAAyB;AACzB,mDAAiC;AACjC,0CAAwB;AACxB,wCAAsB"}
|
package/package.json
CHANGED
package/src/index.ts
CHANGED
package/src/retryBackoff.ts
DELETED
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Retries a function up to a maximum number of times, with exponential backoff.
|
|
3
|
-
* Current settings, max total wait time is ~10 seconds.
|
|
4
|
-
*/
|
|
5
|
-
export async function retryBackoff<T>(
|
|
6
|
-
name: string,
|
|
7
|
-
fn: () => Promise<T>,
|
|
8
|
-
maxRetries = 5,
|
|
9
|
-
backoffFn: (i: number) => number = (i) => Math.min(2000, 250 * 2 ** i),
|
|
10
|
-
): Promise<T> {
|
|
11
|
-
for (let i = 1; ; i++) {
|
|
12
|
-
try {
|
|
13
|
-
return await fn();
|
|
14
|
-
} catch (e) {
|
|
15
|
-
if (i <= maxRetries) {
|
|
16
|
-
const sleepMs = backoffFn(i);
|
|
17
|
-
console.error(
|
|
18
|
-
`[RETRY] ${name} sleeping ${sleepMs}ms after try ${i}, error:`,
|
|
19
|
-
e,
|
|
20
|
-
);
|
|
21
|
-
await new Promise((r) => setTimeout(r, sleepMs));
|
|
22
|
-
} else {
|
|
23
|
-
console.warn(`[RETRY] ${name} QUITTING after try ${i}, error: ${e}`);
|
|
24
|
-
break;
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
// TODO: add performance logging
|
|
29
|
-
throw new Error(`too many retries: ${name}`);
|
|
30
|
-
}
|