flowx-control 1.0.2 → 1.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/README.md +20 -70
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -79,8 +79,7 @@ await limiter.execute(() => callExternalApi());
|
|
|
79
79
|
|
|
80
80
|
### 🛡️ Resilience
|
|
81
81
|
|
|
82
|
-
|
|
83
|
-
<summary><strong>retry</strong> — Retry with backoff & jitter</summary>
|
|
82
|
+
#### retry — Retry with backoff & jitter
|
|
84
83
|
|
|
85
84
|
```ts
|
|
86
85
|
import { retry } from 'flowx-control/retry';
|
|
@@ -95,10 +94,7 @@ const data = await retry(() => fetch('/api'), {
|
|
|
95
94
|
signal: abortController.signal,
|
|
96
95
|
});
|
|
97
96
|
```
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
<details>
|
|
101
|
-
<summary><strong>circuitBreaker</strong> — Stop cascading failures</summary>
|
|
97
|
+
#### circuitBreaker — Stop cascading failures
|
|
102
98
|
|
|
103
99
|
```ts
|
|
104
100
|
import { createCircuitBreaker } from 'flowx-control/circuit-breaker';
|
|
@@ -117,10 +113,7 @@ console.log(breaker.state); // 'closed' | 'open' | 'half-open'
|
|
|
117
113
|
console.log(breaker.failureCount);
|
|
118
114
|
breaker.reset();
|
|
119
115
|
```
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
<details>
|
|
123
|
-
<summary><strong>fallback</strong> — Graceful degradation</summary>
|
|
116
|
+
#### fallback — Graceful degradation
|
|
124
117
|
|
|
125
118
|
```ts
|
|
126
119
|
import { withFallback, fallbackChain } from 'flowx-control/fallback';
|
|
@@ -137,10 +130,7 @@ const result = await fallbackChain([
|
|
|
137
130
|
() => fetchFromFallback(),
|
|
138
131
|
]);
|
|
139
132
|
```
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
<details>
|
|
143
|
-
<summary><strong>timeout</strong> — Never wait forever</summary>
|
|
133
|
+
#### timeout — Never wait forever
|
|
144
134
|
|
|
145
135
|
```ts
|
|
146
136
|
import { withTimeout } from 'flowx-control/timeout';
|
|
@@ -151,12 +141,9 @@ const result = await withTimeout(() => fetch('/slow-api'), 5000, {
|
|
|
151
141
|
signal: controller.signal,
|
|
152
142
|
});
|
|
153
143
|
```
|
|
154
|
-
</details>
|
|
155
|
-
|
|
156
144
|
### 🚦 Concurrency
|
|
157
145
|
|
|
158
|
-
|
|
159
|
-
<summary><strong>bulkhead</strong> — Isolate concurrent operations</summary>
|
|
146
|
+
#### bulkhead — Isolate concurrent operations
|
|
160
147
|
|
|
161
148
|
```ts
|
|
162
149
|
import { createBulkhead } from 'flowx-control/bulkhead';
|
|
@@ -170,10 +157,7 @@ const bulkhead = createBulkhead({
|
|
|
170
157
|
const result = await bulkhead.execute(() => processRequest());
|
|
171
158
|
console.log(bulkhead.activeCount, bulkhead.queueSize);
|
|
172
159
|
```
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
<details>
|
|
176
|
-
<summary><strong>queue</strong> — Priority async task queue</summary>
|
|
160
|
+
#### queue — Priority async task queue
|
|
177
161
|
|
|
178
162
|
```ts
|
|
179
163
|
import { createQueue } from 'flowx-control/queue';
|
|
@@ -187,10 +171,7 @@ await queue.onIdle(); // wait until all done
|
|
|
187
171
|
queue.pause();
|
|
188
172
|
queue.resume();
|
|
189
173
|
```
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
<details>
|
|
193
|
-
<summary><strong>semaphore</strong> — Counting resource lock</summary>
|
|
174
|
+
#### semaphore — Counting resource lock
|
|
194
175
|
|
|
195
176
|
```ts
|
|
196
177
|
import { createSemaphore } from 'flowx-control/semaphore';
|
|
@@ -203,10 +184,7 @@ try {
|
|
|
203
184
|
release();
|
|
204
185
|
}
|
|
205
186
|
```
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
<details>
|
|
209
|
-
<summary><strong>mutex</strong> — Mutual exclusion lock</summary>
|
|
187
|
+
#### mutex — Mutual exclusion lock
|
|
210
188
|
|
|
211
189
|
```ts
|
|
212
190
|
import { createMutex } from 'flowx-control/mutex';
|
|
@@ -219,12 +197,9 @@ try {
|
|
|
219
197
|
release();
|
|
220
198
|
}
|
|
221
199
|
```
|
|
222
|
-
</details>
|
|
223
|
-
|
|
224
200
|
### 🎛️ Flow Control
|
|
225
201
|
|
|
226
|
-
|
|
227
|
-
<summary><strong>rateLimit</strong> — Token bucket rate limiting</summary>
|
|
202
|
+
#### rateLimit — Token bucket rate limiting
|
|
228
203
|
|
|
229
204
|
```ts
|
|
230
205
|
import { createRateLimiter } from 'flowx-control/rate-limit';
|
|
@@ -239,10 +214,7 @@ await limiter.execute(() => callApi());
|
|
|
239
214
|
console.log(limiter.remaining);
|
|
240
215
|
limiter.reset();
|
|
241
216
|
```
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
<details>
|
|
245
|
-
<summary><strong>throttle</strong> — Rate-limit function calls</summary>
|
|
217
|
+
#### throttle — Rate-limit function calls
|
|
246
218
|
|
|
247
219
|
```ts
|
|
248
220
|
import { throttle } from 'flowx-control/throttle';
|
|
@@ -255,10 +227,7 @@ const save = throttle(saveToDb, 1000, {
|
|
|
255
227
|
await save(data);
|
|
256
228
|
save.cancel();
|
|
257
229
|
```
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
<details>
|
|
261
|
-
<summary><strong>debounce</strong> — Delay until activity pauses</summary>
|
|
230
|
+
#### debounce — Delay until activity pauses
|
|
262
231
|
|
|
263
232
|
```ts
|
|
264
233
|
import { debounce } from 'flowx-control/debounce';
|
|
@@ -273,10 +242,7 @@ await search(query);
|
|
|
273
242
|
await search.flush();
|
|
274
243
|
search.cancel();
|
|
275
244
|
```
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
<details>
|
|
279
|
-
<summary><strong>batch</strong> — Process collections in chunks</summary>
|
|
245
|
+
#### batch — Process collections in chunks
|
|
280
246
|
|
|
281
247
|
```ts
|
|
282
248
|
import { batch } from 'flowx-control/batch';
|
|
@@ -292,10 +258,7 @@ const result = await batch(urls, async (url, i) => {
|
|
|
292
258
|
|
|
293
259
|
console.log(result.succeeded, result.failed, result.errors);
|
|
294
260
|
```
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
<details>
|
|
298
|
-
<summary><strong>pipeline</strong> — Compose async operations</summary>
|
|
261
|
+
#### pipeline — Compose async operations
|
|
299
262
|
|
|
300
263
|
```ts
|
|
301
264
|
import { pipeline, pipe } from 'flowx-control/pipeline';
|
|
@@ -308,12 +271,9 @@ const transform = pipe(
|
|
|
308
271
|
|
|
309
272
|
const result = await transform(' hello world ');
|
|
310
273
|
```
|
|
311
|
-
</details>
|
|
312
|
-
|
|
313
274
|
### 🛠️ Utilities
|
|
314
275
|
|
|
315
|
-
|
|
316
|
-
<summary><strong>poll</strong> — Repeated polling with backoff</summary>
|
|
276
|
+
#### poll — Repeated polling with backoff
|
|
317
277
|
|
|
318
278
|
```ts
|
|
319
279
|
import { poll } from 'flowx-control/poll';
|
|
@@ -328,10 +288,7 @@ const { result, stop } = poll(() => checkJobStatus(jobId), {
|
|
|
328
288
|
|
|
329
289
|
const finalStatus = await result;
|
|
330
290
|
```
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
<details>
|
|
334
|
-
<summary><strong>hedge</strong> — Hedged/speculative requests</summary>
|
|
291
|
+
#### hedge — Hedged/speculative requests
|
|
335
292
|
|
|
336
293
|
```ts
|
|
337
294
|
import { hedge } from 'flowx-control/hedge';
|
|
@@ -342,10 +299,7 @@ const data = await hedge(() => fetch('/api'), {
|
|
|
342
299
|
maxHedges: 2,
|
|
343
300
|
});
|
|
344
301
|
```
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
<details>
|
|
348
|
-
<summary><strong>memo</strong> — Async memoization with TTL</summary>
|
|
302
|
+
#### memo — Async memoization with TTL
|
|
349
303
|
|
|
350
304
|
```ts
|
|
351
305
|
import { memo } from 'flowx-control/memo';
|
|
@@ -359,10 +313,7 @@ const cachedFetch = memo(fetchUserById, {
|
|
|
359
313
|
const user = await cachedFetch(123);
|
|
360
314
|
cachedFetch.clear();
|
|
361
315
|
```
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
<details>
|
|
365
|
-
<summary><strong>deferred</strong> — Externally resolvable promise</summary>
|
|
316
|
+
#### deferred — Externally resolvable promise
|
|
366
317
|
|
|
367
318
|
```ts
|
|
368
319
|
import { deferred } from 'flowx-control/deferred';
|
|
@@ -371,8 +322,6 @@ const d = deferred<string>();
|
|
|
371
322
|
setTimeout(() => d.resolve('hello'), 1000);
|
|
372
323
|
const value = await d.promise; // 'hello'
|
|
373
324
|
```
|
|
374
|
-
</details>
|
|
375
|
-
|
|
376
325
|
---
|
|
377
326
|
|
|
378
327
|
## Deep Imports (Tree-shaking)
|
|
@@ -428,8 +377,8 @@ try {
|
|
|
428
377
|
## Contributing
|
|
429
378
|
|
|
430
379
|
```bash
|
|
431
|
-
git clone https://github.com/Avinashvelu03/
|
|
432
|
-
cd
|
|
380
|
+
git clone https://github.com/Avinashvelu03/flowx-control.git
|
|
381
|
+
cd flowx-control
|
|
433
382
|
npm install
|
|
434
383
|
npm test # Run tests with 100% coverage
|
|
435
384
|
npm run lint # ESLint
|
|
@@ -441,3 +390,4 @@ npm run build # Build ESM + CJS + DTS
|
|
|
441
390
|
## License
|
|
442
391
|
|
|
443
392
|
MIT © [Avinash](https://github.com/Avinashvelu03)
|
|
393
|
+
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "flowx-control",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.4",
|
|
4
4
|
"description": "Production-grade, zero-dependency TypeScript resilience & async flow control library. 100% test coverage. Retry with backoff, Circuit Breaker, Bulkhead, Rate Limiter, Priority Queue, Semaphore, Mutex, Debounce, Throttle, Timeout, Hedge, Poll, Batch, Pipeline — all tree-shakable & composable.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.mjs",
|
|
@@ -143,12 +143,12 @@
|
|
|
143
143
|
"license": "MIT",
|
|
144
144
|
"repository": {
|
|
145
145
|
"type": "git",
|
|
146
|
-
"url": "git+https://github.com/Avinashvelu03/
|
|
146
|
+
"url": "git+https://github.com/Avinashvelu03/flowx-control.git"
|
|
147
147
|
},
|
|
148
148
|
"bugs": {
|
|
149
|
-
"url": "https://github.com/Avinashvelu03/
|
|
149
|
+
"url": "https://github.com/Avinashvelu03/flowx-control/issues"
|
|
150
150
|
},
|
|
151
|
-
"homepage": "https://github.com/Avinashvelu03/
|
|
151
|
+
"homepage": "https://github.com/Avinashvelu03/flowx-control#readme",
|
|
152
152
|
"devDependencies": {
|
|
153
153
|
"@types/jest": "^29.5.14",
|
|
154
154
|
"@typescript-eslint/eslint-plugin": "^7.0.0",
|