safe-timeouts 0.1.0 → 0.1.2
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 +20 -18
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
1
|
-
# safe-
|
|
1
|
+
# safe-timeouts
|
|
2
2
|
|
|
3
3
|
**Deadline-based timeouts for async Node.js code with AbortSignal support.**
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
10
12
|
|
|
11
|
-
Promise-based deadline enforcement for async code in Node.js. `safe-
|
|
13
|
+
Promise-based deadline enforcement for async code in Node.js. `safe-timeouts` helps you apply a **single execution deadline** across async functions, services, and external calls using standard `AbortSignal` semantics.
|
|
12
14
|
|
|
13
15
|
---
|
|
14
16
|
|
|
@@ -26,14 +28,14 @@ Most timeout utilities fail here because they:
|
|
|
26
28
|
* don’t compose across nested calls
|
|
27
29
|
* don’t integrate with `AbortSignal`
|
|
28
30
|
|
|
29
|
-
`safe-
|
|
31
|
+
`safe-timeouts` solves this correctly.
|
|
30
32
|
|
|
31
33
|
---
|
|
32
34
|
|
|
33
35
|
## Installation
|
|
34
36
|
|
|
35
37
|
```bash
|
|
36
|
-
npm install safe-
|
|
38
|
+
npm install safe-timeouts
|
|
37
39
|
```
|
|
38
40
|
|
|
39
41
|
Node.js >= 16 is required.
|
|
@@ -43,7 +45,7 @@ Node.js >= 16 is required.
|
|
|
43
45
|
## Basic usage
|
|
44
46
|
|
|
45
47
|
```ts
|
|
46
|
-
import { withTimeout, TimeoutError } from "safe-
|
|
48
|
+
import { withTimeout, TimeoutError } from "safe-timeouts";
|
|
47
49
|
import axios from "axios";
|
|
48
50
|
|
|
49
51
|
try {
|
|
@@ -159,7 +161,7 @@ These **cannot be forcibly stopped**:
|
|
|
159
161
|
* CPU-bound loops
|
|
160
162
|
* legacy libraries
|
|
161
163
|
|
|
162
|
-
For these, `safe-
|
|
164
|
+
For these, `safe-timeouts`:
|
|
163
165
|
|
|
164
166
|
* stops waiting
|
|
165
167
|
* rejects the outer promise
|
|
@@ -173,7 +175,7 @@ JavaScript cannot forcibly stop non-abort-aware operations (like `setTimeout`, S
|
|
|
173
175
|
|
|
174
176
|
When such operations exceed the deadline:
|
|
175
177
|
|
|
176
|
-
* `safe-
|
|
178
|
+
* `safe-timeouts` rejects the outer promise
|
|
177
179
|
* abort-aware APIs are cancelled automatically
|
|
178
180
|
* JavaScript execution resumes only when the pending operation completes
|
|
179
181
|
|
|
@@ -188,11 +190,11 @@ This design avoids hidden global checks while remaining honest about JavaScript
|
|
|
188
190
|
|
|
189
191
|
## Axios integration
|
|
190
192
|
|
|
191
|
-
`safe-
|
|
193
|
+
`safe-timeouts` works with Axios by passing the provided `AbortSignal` to the request.
|
|
192
194
|
|
|
193
195
|
```ts
|
|
194
196
|
import axios from "axios";
|
|
195
|
-
import { withTimeout } from "safe-
|
|
197
|
+
import { withTimeout } from "safe-timeouts";
|
|
196
198
|
|
|
197
199
|
await withTimeout(2000, async (signal) => {
|
|
198
200
|
const res = await axios.get("/users", { signal });
|
|
@@ -209,7 +211,7 @@ This explicit integration keeps cancellation predictable and avoids hidden behav
|
|
|
209
211
|
|
|
210
212
|
---
|
|
211
213
|
|
|
212
|
-
## What `safe-
|
|
214
|
+
## What `safe-timeouts` does NOT do
|
|
213
215
|
|
|
214
216
|
It is important to be explicit about limitations:
|
|
215
217
|
|
|
@@ -224,7 +226,7 @@ This matches the realities of Node.js and modern async runtimes.
|
|
|
224
226
|
|
|
225
227
|
## How this differs from `setTimeout`
|
|
226
228
|
|
|
227
|
-
| Feature | setTimeout | safe-
|
|
229
|
+
| Feature | setTimeout | safe-timeouts |
|
|
228
230
|
| ------------------- | ---------- | ------------ |
|
|
229
231
|
| End-to-end deadline | ❌ | ✅ |
|
|
230
232
|
| Nested composition | ❌ | ✅ |
|
|
@@ -232,7 +234,7 @@ This matches the realities of Node.js and modern async runtimes.
|
|
|
232
234
|
| Context propagation | ❌ | ✅ |
|
|
233
235
|
| Concurrency-safe | ❌ | ✅ |
|
|
234
236
|
|
|
235
|
-
`setTimeout` works locally. `safe-
|
|
237
|
+
`setTimeout` works locally. `safe-timeouts` works across your entire async call graph.
|
|
236
238
|
|
|
237
239
|
---
|
|
238
240
|
|
|
@@ -262,7 +264,7 @@ instanceof TimeoutError === true
|
|
|
262
264
|
|
|
263
265
|
## When to use this
|
|
264
266
|
|
|
265
|
-
Use `safe-
|
|
267
|
+
Use `safe-timeouts` when:
|
|
266
268
|
|
|
267
269
|
* you want request-level deadlines
|
|
268
270
|
* you call multiple async services
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "safe-timeouts",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.2",
|
|
4
4
|
"description": "Deadline-based timeouts for async code in Node.js. Enforce end-to-end execution deadlines with automatic propagation and AbortSignal support.",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"module": "./dist/index.mjs",
|