dynamic-throttled-queue 2.2.0-rc.7fbd417 → 2.2.0-rc.a788b24

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 CHANGED
@@ -149,22 +149,7 @@ The normalized outcomes are `{ kind: "returned-false" }`, `{ kind: "thrown", err
149
149
 
150
150
  ### Rate strategies
151
151
 
152
- The default `linear` strategy preserves the adaptive behavior above: it changes the rate by one request per interval. Use `aimd` when a capacity signal should reduce throughput more quickly while recovery remains gradual. AIMD increases by a fixed amount after a clean eligible observation window and reduces the rate by a multiplier when the error threshold is reached.
153
-
154
- ```ts
155
- import { aimd, createThrottledQueue } from "dynamic-throttled-queue";
156
-
157
- const throttle = createThrottledQueue({
158
- min_rpi: 1,
159
- max_rpi: 100,
160
- interval: 1000,
161
- rateStrategy: aimd({ increaseBy: 2, decreaseFactor: 0.5 }),
162
- });
163
- ```
164
-
165
- `aimd()` defaults to `{ increaseBy: 1, decreaseFactor: 0.5 }`. `increaseBy` must be a positive integer; `decreaseFactor` must be greater than `0` and less than `1`. AIMD uses `Math.floor(currentRate * decreaseFactor)` when reducing the rate, then the queue applies its configured `min_rpi` and `max_rpi` bounds. Like `linear`, it holds steady for partial-error, empty, and immediately-post-backoff observation windows.
166
-
167
- You can also import and pass `linear` explicitly, or provide a custom pure strategy:
152
+ The default `linear` strategy preserves the adaptive behavior above. You can import and pass it explicitly, or provide a custom pure strategy:
168
153
 
169
154
  ```ts
170
155
  import {
@@ -12,10 +12,6 @@ export type RateStrategyDecision = Readonly<{
12
12
  shouldBackOff: boolean;
13
13
  }>;
14
14
  export type RateStrategy = (observation: RateStrategyObservation) => RateStrategyDecision;
15
- export type AimdOptions = {
16
- increaseBy?: number;
17
- decreaseFactor?: number;
18
- };
19
15
  export type RateFailureOutcome = Readonly<{
20
16
  kind: "returned-false";
21
17
  }> | Readonly<{
@@ -27,7 +23,6 @@ export type RateFailureOutcome = Readonly<{
27
23
  }>;
28
24
  export type RateOutcomeClassifier = (outcome: RateFailureOutcome) => boolean;
29
25
  export declare const linear: RateStrategy;
30
- export declare function aimd({ increaseBy, decreaseFactor }?: AimdOptions): RateStrategy;
31
26
  /** Return `false` to signal failure (increments error count, triggers retry if configured). */
32
27
  export type ThrottleCallback = () => boolean | void | Promise<boolean | void>;
33
28
  export type ThrottleOptions = {
@@ -9,23 +9,6 @@ export const linear = ({ minRate, maxRate, currentRate, errorCount, errorThresho
9
9
  }
10
10
  return { nextRate: currentRate, shouldBackOff: false };
11
11
  };
12
- export function aimd({ increaseBy = 1, decreaseFactor = 0.5 } = {}) {
13
- if (!Number.isInteger(increaseBy) || increaseBy < 1) {
14
- throw new Error("increaseBy must be a positive integer");
15
- }
16
- if (!Number.isFinite(decreaseFactor) || decreaseFactor <= 0 || decreaseFactor >= 1) {
17
- throw new Error("decreaseFactor must be a number greater than 0 and less than 1");
18
- }
19
- return ({ currentRate, errorCount, errorThreshold, hasPendingWork, wasBackedOff }) => {
20
- if (errorCount >= errorThreshold) {
21
- return { nextRate: Math.floor(currentRate * decreaseFactor), shouldBackOff: true };
22
- }
23
- if (!wasBackedOff && errorCount === 0 && hasPendingWork) {
24
- return { nextRate: currentRate + increaseBy, shouldBackOff: false };
25
- }
26
- return { nextRate: currentRate, shouldBackOff: false };
27
- };
28
- }
29
12
  export function createThrottledQueue(options) {
30
13
  const { min_rpi, interval, max_rpi = min_rpi, concurrency, retry = 0, compact_threshold = 512 } = options;
31
14
  const errors_per_interval = options.errors_per_interval ?? 5;
@@ -1 +1 @@
1
- {"version":3,"file":"dynamic-throttled-queue.js","sourceRoot":"","sources":["../src/dynamic-throttled-queue.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,6BAA6B;AAC5D,OAAO,EAAE,eAAe,EAAE,uBAAuB;AA+BjD,MAAM,CAAC,MAAM,MAAM,GAAiB,CAAC,EACnC,OAAO,EACP,OAAO,EACP,WAAW,EACX,UAAU,EACV,cAAc,EACd,cAAc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I,KAAK,CAAC,sCAAsC,CAAC,CAAC;IAC1D,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,iBAAiB,CAAC,IAAI,iBAAiB,GAAG,CAAC,EAAE,CAAC;QAClE,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,eAAe,CAAC,OAAO,EAAE,oBAAoB,CAAC;QACnD,OAAO;QACP,OAAO;QACP,mBAAmB;KACpB,EAAE,OAAO,CAAC,YAAY,IAAI,MAAM,CAAC,CAAC,CAAC;AACtC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dynamic-throttled-queue",
3
- "version": "2.2.0-rc.7fbd417",
3
+ "version": "2.2.0-rc.a788b24",
4
4
  "type": "module",
5
5
  "description": "Dynamically throttles arbitrary code to execute between a minimum and maximum number of times per interval. Best for making throttled API requests.",
6
6
  "files": [