@sdxc/backoff 0.0.0-pre.1 → 2026.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/README.md +13 -3
- package/package.json +13 -4
package/README.md
CHANGED
|
@@ -122,16 +122,26 @@ export default {
|
|
|
122
122
|
|
|
123
123
|
## Pattern: Honoring Retry-After
|
|
124
124
|
|
|
125
|
-
When a server says how long to wait, wait at least that long.
|
|
125
|
+
When a server says how long to wait, wait at least that long. `Retry-After` is either a number of seconds or an HTTP date, so read both, and treat anything else as no answer.
|
|
126
126
|
|
|
127
127
|
```typescript
|
|
128
128
|
import { createBackoff } from "@sdxc/backoff";
|
|
129
129
|
|
|
130
130
|
let backoff = createBackoff({ base: "1 second", max: "5 minutes", jitter: "full" });
|
|
131
131
|
|
|
132
|
+
function retryAfterMs(response: Response, now: number): number {
|
|
133
|
+
let header = response.headers.get("retry-after");
|
|
134
|
+
if (header === null) return 0;
|
|
135
|
+
|
|
136
|
+
let seconds = Number(header);
|
|
137
|
+
if (Number.isFinite(seconds)) return Math.max(seconds * 1000, 0);
|
|
138
|
+
|
|
139
|
+
let date = Date.parse(header);
|
|
140
|
+
return Number.isNaN(date) ? 0 : Math.max(date - now, 0);
|
|
141
|
+
}
|
|
142
|
+
|
|
132
143
|
function waitAfter(response: Response, attempt: number): number {
|
|
133
|
-
|
|
134
|
-
return Math.max(retryAfterMs, backoff.delay(attempt));
|
|
144
|
+
return Math.max(retryAfterMs(response, Date.now()), backoff.delay(attempt));
|
|
135
145
|
}
|
|
136
146
|
```
|
|
137
147
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sdxc/backoff",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2026.10.6",
|
|
4
4
|
"description": "Retry delay schedules with exponential, linear, constant or stepped growth, a ceiling, free attempts and seedable jitter",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -8,10 +8,10 @@
|
|
|
8
8
|
".": "./dist/index.js"
|
|
9
9
|
},
|
|
10
10
|
"dependencies": {
|
|
11
|
-
"@sdxc/duration": "2026.10.
|
|
12
|
-
"@sdxc/random": "
|
|
11
|
+
"@sdxc/duration": "2026.10.6",
|
|
12
|
+
"@sdxc/random": "2026.10.6"
|
|
13
13
|
},
|
|
14
|
-
"gitHead": "
|
|
14
|
+
"gitHead": "b1067eb20fc47ec51ff8c4de47d07dc3f9c00466",
|
|
15
15
|
"publishConfig": {
|
|
16
16
|
"access": "public"
|
|
17
17
|
},
|
|
@@ -19,5 +19,14 @@
|
|
|
19
19
|
"type": "git",
|
|
20
20
|
"url": "git+https://github.com/sergiodxa/monorepo.git",
|
|
21
21
|
"directory": "packages/backoff"
|
|
22
|
+
},
|
|
23
|
+
"homepage": "https://sdxc.sergiodxa.com/api/backoff",
|
|
24
|
+
"author": {
|
|
25
|
+
"name": "Sergio Xalambrí",
|
|
26
|
+
"url": "https://sergiodxa.com"
|
|
27
|
+
},
|
|
28
|
+
"funding": {
|
|
29
|
+
"type": "github",
|
|
30
|
+
"url": "https://github.com/sponsors/sergiodxa"
|
|
22
31
|
}
|
|
23
32
|
}
|