adaptive-concurrency 0.8.0 → 0.9.1
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/Limiter.d.ts +4 -2
- package/dist/Limiter.d.ts.map +1 -1
- package/dist/Limiter.js +26 -18
- package/dist/MetricRegistry.d.ts +6 -0
- package/dist/MetricRegistry.d.ts.map +1 -1
- package/dist/MetricRegistry.js +6 -0
- package/package.json +2 -1
- package/dist/limiter/allocation-unavailable-strategies/FifoBlockingRejection.d.ts +0 -30
- package/dist/limiter/allocation-unavailable-strategies/FifoBlockingRejection.d.ts.map +0 -1
- package/dist/limiter/allocation-unavailable-strategies/FifoBlockingRejection.js +0 -29
- package/dist/limiter/allocation-unavailable-strategies/LifoBlockingRejection.d.ts +0 -27
- package/dist/limiter/allocation-unavailable-strategies/LifoBlockingRejection.d.ts.map +0 -1
- package/dist/limiter/allocation-unavailable-strategies/LifoBlockingRejection.js +0 -27
package/dist/Limiter.d.ts
CHANGED
|
@@ -113,11 +113,13 @@ export declare class Limiter<Context = void> {
|
|
|
113
113
|
private readonly acquireStrategy;
|
|
114
114
|
private readonly rejectionStrategy;
|
|
115
115
|
private readonly bypassResolver;
|
|
116
|
+
private readonly acquireBypassedAllotment;
|
|
116
117
|
private readonly successCounter;
|
|
117
118
|
private readonly droppedCounter;
|
|
118
119
|
private readonly ignoredCounter;
|
|
119
|
-
private readonly
|
|
120
|
-
private readonly
|
|
120
|
+
private readonly acquireSucceededCounter;
|
|
121
|
+
private readonly acquireFailedCounter;
|
|
122
|
+
private readonly acquireBypassedCounter;
|
|
121
123
|
private readonly limitGauge;
|
|
122
124
|
static makeDefaultLimit(): AdaptiveLimit;
|
|
123
125
|
constructor(options?: LimiterOptions<Context>);
|
package/dist/Limiter.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Limiter.d.ts","sourceRoot":"","sources":["../src/Limiter.ts"],"names":[],"mappings":"AACA,OAAO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AK,EACzB,OAAO,EAAE,cAAc,CAAC,QAAQ,CAAC,EACjC,EAAE,EAAE,CACF,IAAI,EAAE,eAAe,CAAC,QAAQ,CAAC,KAC5B,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,OAAO,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GACtD,OAAO,CAAC,CAAC,GAAG,OAAO,iBAAiB,CAAC,CAAC;CAC1C;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,WAAW,CAAC,QAAQ,EAClC,OAAO,EAAE,OAAO,CAAC,QAAQ,CAAC,GACzB,eAAe,CAAC,QAAQ,CAAC,CAmE3B"}
|
package/dist/Limiter.js
CHANGED
|
@@ -5,11 +5,6 @@ import { isAdaptiveTimeoutError, isRunResult, QuotaNotAvailable, } from "./RunRe
|
|
|
5
5
|
// ---------------------------------------------------------------------------
|
|
6
6
|
// Limiter options
|
|
7
7
|
// ---------------------------------------------------------------------------
|
|
8
|
-
const NOOP_ALLOTMENT = {
|
|
9
|
-
async releaseAndRecordSuccess() { },
|
|
10
|
-
async releaseAndIgnore() { },
|
|
11
|
-
async releaseAndRecordDropped() { },
|
|
12
|
-
};
|
|
13
8
|
let idCounter = 0;
|
|
14
9
|
/**
|
|
15
10
|
* Concurrency limiter with pluggable strategies for gating decisions and
|
|
@@ -25,11 +20,13 @@ export class Limiter {
|
|
|
25
20
|
acquireStrategy;
|
|
26
21
|
rejectionStrategy;
|
|
27
22
|
bypassResolver;
|
|
23
|
+
acquireBypassedAllotment;
|
|
28
24
|
successCounter;
|
|
29
25
|
droppedCounter;
|
|
30
26
|
ignoredCounter;
|
|
31
|
-
|
|
32
|
-
|
|
27
|
+
acquireSucceededCounter;
|
|
28
|
+
acquireFailedCounter;
|
|
29
|
+
acquireBypassedCounter;
|
|
33
30
|
limitGauge;
|
|
34
31
|
static makeDefaultLimit() {
|
|
35
32
|
return new GradientLimit();
|
|
@@ -66,29 +63,37 @@ export class Limiter {
|
|
|
66
63
|
id: limiterName,
|
|
67
64
|
status: "ignored",
|
|
68
65
|
});
|
|
69
|
-
this.
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
66
|
+
this.acquireSucceededCounter = registry.counter(MetricIds.ACQUIRE_ATTEMPT_NAME, { id: limiterName, status: "succeeded" });
|
|
67
|
+
this.acquireFailedCounter = registry.counter(MetricIds.ACQUIRE_ATTEMPT_NAME, { id: limiterName, status: "failed" });
|
|
68
|
+
this.acquireBypassedCounter = registry.counter(MetricIds.ACQUIRE_ATTEMPT_NAME, { id: limiterName, status: "bypassed" });
|
|
69
|
+
this.acquireBypassedAllotment = {
|
|
70
|
+
releaseAndRecordSuccess: async () => {
|
|
71
|
+
this.successCounter.increment();
|
|
72
|
+
},
|
|
73
|
+
releaseAndIgnore: async () => {
|
|
74
|
+
this.ignoredCounter.increment();
|
|
75
|
+
},
|
|
76
|
+
releaseAndRecordDropped: async () => {
|
|
77
|
+
this.droppedCounter.increment();
|
|
78
|
+
},
|
|
79
|
+
};
|
|
80
|
+
// Emit metric for initial limit.
|
|
81
|
+
this.limitGauge.record(this._limit);
|
|
77
82
|
}
|
|
78
83
|
async acquire(options) {
|
|
79
84
|
if (options?.signal?.aborted)
|
|
80
85
|
return undefined;
|
|
81
86
|
const ctx = (options?.context ?? undefined);
|
|
82
87
|
if (this.bypassResolver?.(ctx)) {
|
|
83
|
-
this.
|
|
84
|
-
return
|
|
88
|
+
this.acquireBypassedCounter.increment();
|
|
89
|
+
return this.acquireBypassedAllotment;
|
|
85
90
|
}
|
|
86
91
|
const state = {
|
|
87
92
|
limit: this._limit,
|
|
88
93
|
inflight: this._inflight,
|
|
89
94
|
};
|
|
90
95
|
if (!(await this.acquireStrategy.tryAcquireAllotment(ctx, state))) {
|
|
91
|
-
this.
|
|
96
|
+
this.acquireFailedCounter.increment();
|
|
92
97
|
if (!this.rejectionStrategy) {
|
|
93
98
|
return undefined;
|
|
94
99
|
}
|
|
@@ -103,6 +108,7 @@ export class Limiter {
|
|
|
103
108
|
return this.tryAcquireCore(retryCtx);
|
|
104
109
|
}, options?.signal);
|
|
105
110
|
}
|
|
111
|
+
this.acquireSucceededCounter.increment();
|
|
106
112
|
const allotment = this.createAllotment(ctx);
|
|
107
113
|
if (options?.signal?.aborted) {
|
|
108
114
|
// here, we did acquire, so we need to try to cleanup.
|
|
@@ -117,8 +123,10 @@ export class Limiter {
|
|
|
117
123
|
inflight: this._inflight,
|
|
118
124
|
};
|
|
119
125
|
if (!(await this.acquireStrategy.tryAcquireAllotment(ctx, state))) {
|
|
126
|
+
this.acquireFailedCounter.increment();
|
|
120
127
|
return undefined;
|
|
121
128
|
}
|
|
129
|
+
this.acquireSucceededCounter.increment();
|
|
122
130
|
return this.createAllotment(ctx);
|
|
123
131
|
}
|
|
124
132
|
createAllotment(ctx) {
|
package/dist/MetricRegistry.d.ts
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Common metric ids used by the limiters and limit algorithms.
|
|
3
|
+
*
|
|
4
|
+
* `CALL_NAME` records outcomes for work that actually executed under a limiter
|
|
5
|
+
* (status: `success`, `ignored`, `dropped`). `ACQUIRE_ATTEMPT_NAME` records
|
|
6
|
+
* acquire outcomes (status: `succeeded`, `failed`, `bypassed`), including
|
|
7
|
+
* failures from retry attempts.
|
|
3
8
|
*/
|
|
4
9
|
export declare const MetricIds: {
|
|
5
10
|
readonly LIMIT_NAME: "limit";
|
|
6
11
|
readonly CALL_NAME: "call";
|
|
12
|
+
readonly ACQUIRE_ATTEMPT_NAME: "acquire_attempt";
|
|
7
13
|
readonly INFLIGHT_NAME: "inflight";
|
|
8
14
|
readonly PARTITION_LIMIT_NAME: "limit.partition";
|
|
9
15
|
readonly MIN_RTT_NAME: "min_rtt";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MetricRegistry.d.ts","sourceRoot":"","sources":["../src/MetricRegistry.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"MetricRegistry.d.ts","sourceRoot":"","sources":["../src/MetricRegistry.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,eAAO,MAAM,SAAS;;;;;;;;;CASZ,CAAC;AAEX;;GAEG;AACH,MAAM,WAAW,kBAAkB;IACjC,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,OAAO;IACtB,SAAS,IAAI,IAAI,CAAC;CACnB;AAED,0FAA0F;AAC1F,MAAM,WAAW,KAAK;IACpB,MAAM,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;CAC7B;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;;;;;;;OAQG;IACH,YAAY,CACV,EAAE,EAAE,MAAM,EACV,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAClC,kBAAkB,CAAC;IAEtB;;;;;;;;OAQG;IACH,KAAK,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,KAAK,CAAC;IAE9D;;;;;OAKG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,OAAO,CAAC;CACnE;AAMD;;;GAGG;AACH,eAAO,MAAM,kBAAkB,EAAE,cAUhC,CAAC"}
|
package/dist/MetricRegistry.js
CHANGED
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Common metric ids used by the limiters and limit algorithms.
|
|
3
|
+
*
|
|
4
|
+
* `CALL_NAME` records outcomes for work that actually executed under a limiter
|
|
5
|
+
* (status: `success`, `ignored`, `dropped`). `ACQUIRE_ATTEMPT_NAME` records
|
|
6
|
+
* acquire outcomes (status: `succeeded`, `failed`, `bypassed`), including
|
|
7
|
+
* failures from retry attempts.
|
|
3
8
|
*/
|
|
4
9
|
export const MetricIds = {
|
|
5
10
|
LIMIT_NAME: "limit",
|
|
6
11
|
CALL_NAME: "call",
|
|
12
|
+
ACQUIRE_ATTEMPT_NAME: "acquire_attempt",
|
|
7
13
|
INFLIGHT_NAME: "inflight",
|
|
8
14
|
PARTITION_LIMIT_NAME: "limit.partition",
|
|
9
15
|
MIN_RTT_NAME: "min_rtt",
|
package/package.json
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
"dynamic rate limiting"
|
|
10
10
|
],
|
|
11
11
|
"author": "Ethan Resnick <ethan.resnick@gmail.com>",
|
|
12
|
-
"version": "0.
|
|
12
|
+
"version": "0.9.1",
|
|
13
13
|
"type": "module",
|
|
14
14
|
"exports": {
|
|
15
15
|
".": {
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
"prepublishOnly": "pnpm build"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
|
+
"@types/node": "^25.5.0",
|
|
29
30
|
"tsx": "^4.19.0",
|
|
30
31
|
"type-fest": "^5.5.0",
|
|
31
32
|
"type-party": "^0.7.3",
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import type { AcquireResult, AllotmentUnavailableStrategy } from "../../Limiter.js";
|
|
2
|
-
export type FifoBlockingRejectionOptions<ContextT> = {
|
|
3
|
-
/**
|
|
4
|
-
* Maximum number of blocked callers in the backlog.
|
|
5
|
-
* Default: unbounded
|
|
6
|
-
*/
|
|
7
|
-
backlogSize?: number | undefined;
|
|
8
|
-
/**
|
|
9
|
-
* Maximum timeout for callers blocked on the limiter, in milliseconds.
|
|
10
|
-
* Can be a fixed number or a function that derives the timeout from the
|
|
11
|
-
* request context (e.g. from a deadline). Default: 3_600_000 (1 hour).
|
|
12
|
-
*/
|
|
13
|
-
backlogTimeout?: number | ((context: ContextT) => number) | undefined;
|
|
14
|
-
};
|
|
15
|
-
/**
|
|
16
|
-
* Rejection strategy that blocks the caller in a FIFO queue when the limit
|
|
17
|
-
* has been reached, waiting for a slot to open up. This strategy favors
|
|
18
|
-
* fairness: callers are served in the order they arrived.
|
|
19
|
-
*
|
|
20
|
-
* Because JavaScript is single-threaded, "blocking" means awaiting a promise
|
|
21
|
-
* that resolves when a token becomes available.
|
|
22
|
-
*/
|
|
23
|
-
export declare class FifoBlockingRejection<ContextT> implements AllotmentUnavailableStrategy<ContextT> {
|
|
24
|
-
private readonly delegate;
|
|
25
|
-
constructor(options?: FifoBlockingRejectionOptions<ContextT>);
|
|
26
|
-
onAllotmentUnavailable(context: ContextT, retry: (context: ContextT) => AcquireResult, signal?: AbortSignal): Promise<import("../../LimitAllotment.js").LimitAllotment | undefined>;
|
|
27
|
-
onAllotmentReleased(): Promise<void>;
|
|
28
|
-
onLimitChanged(oldLimit: number, newLimit: number): void;
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=FifoBlockingRejection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"FifoBlockingRejection.d.ts","sourceRoot":"","sources":["../../../src/limiter/allocation-unavailable-strategies/FifoBlockingRejection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,4BAA4B,EAC7B,MAAM,kBAAkB,CAAC;AAO1B,MAAM,MAAM,4BAA4B,CAAC,QAAQ,IAAI;IACnD;;;OAGG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CACvE,CAAC;AAEF;;;;;;;GAOG;AACH,qBAAa,qBAAqB,CAChC,QAAQ,CACR,YAAW,4BAA4B,CAAC,QAAQ,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;gBAElD,OAAO,GAAE,4BAA4B,CAAC,QAAQ,CAAM;IAQhE,sBAAsB,CACpB,OAAO,EAAE,QAAQ,EACjB,KAAK,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,aAAa,EAC3C,MAAM,CAAC,EAAE,WAAW;IAKtB,mBAAmB;IAInB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;CAGzD"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { LinkedWaiterQueue } from "../../utils/LinkedWaiterQueue.js";
|
|
2
|
-
import { BlockingBacklogRejection, MAX_TIMEOUT, } from "./BlockingBacklogRejection.js";
|
|
3
|
-
/**
|
|
4
|
-
* Rejection strategy that blocks the caller in a FIFO queue when the limit
|
|
5
|
-
* has been reached, waiting for a slot to open up. This strategy favors
|
|
6
|
-
* fairness: callers are served in the order they arrived.
|
|
7
|
-
*
|
|
8
|
-
* Because JavaScript is single-threaded, "blocking" means awaiting a promise
|
|
9
|
-
* that resolves when a token becomes available.
|
|
10
|
-
*/
|
|
11
|
-
export class FifoBlockingRejection {
|
|
12
|
-
delegate;
|
|
13
|
-
constructor(options = {}) {
|
|
14
|
-
this.delegate = new BlockingBacklogRejection({
|
|
15
|
-
backlogSize: options.backlogSize ?? Number.POSITIVE_INFINITY,
|
|
16
|
-
backlogTimeout: options.backlogTimeout ?? MAX_TIMEOUT,
|
|
17
|
-
queue: new LinkedWaiterQueue("back"),
|
|
18
|
-
});
|
|
19
|
-
}
|
|
20
|
-
onAllotmentUnavailable(context, retry, signal) {
|
|
21
|
-
return this.delegate.onAllotmentUnavailable(context, retry, signal);
|
|
22
|
-
}
|
|
23
|
-
onAllotmentReleased() {
|
|
24
|
-
return this.delegate.onAllotmentReleased();
|
|
25
|
-
}
|
|
26
|
-
onLimitChanged(oldLimit, newLimit) {
|
|
27
|
-
this.delegate.onLimitChanged(oldLimit, newLimit);
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import type { AcquireResult, AllotmentUnavailableStrategy } from "../../Limiter.js";
|
|
2
|
-
export interface LifoBlockingRejectionOptions<ContextT> {
|
|
3
|
-
/**
|
|
4
|
-
* Maximum number of blocked callers in the backlog. Default: 100
|
|
5
|
-
*/
|
|
6
|
-
backlogSize?: number | undefined;
|
|
7
|
-
/**
|
|
8
|
-
* Maximum timeout for callers blocked on the limiter, in milliseconds.
|
|
9
|
-
* Can be a fixed number or a function that derives the timeout from the
|
|
10
|
-
* request context (e.g. from a deadline). Default: 1000
|
|
11
|
-
*/
|
|
12
|
-
backlogTimeout?: number | ((context: ContextT) => number) | undefined;
|
|
13
|
-
}
|
|
14
|
-
/**
|
|
15
|
-
* Rejection strategy that blocks the caller in a LIFO queue when the limit
|
|
16
|
-
* has been reached. This strategy favors availability over latency by
|
|
17
|
-
* processing the most recently blocked request first, keeping success
|
|
18
|
-
* latencies low and minimizing timeouts.
|
|
19
|
-
*/
|
|
20
|
-
export declare class LifoBlockingRejection<ContextT> implements AllotmentUnavailableStrategy<ContextT> {
|
|
21
|
-
private readonly delegate;
|
|
22
|
-
constructor(options?: LifoBlockingRejectionOptions<ContextT>);
|
|
23
|
-
onAllotmentUnavailable(context: ContextT, retry: (context: ContextT) => AcquireResult, signal?: AbortSignal): Promise<import("../../LimitAllotment.js").LimitAllotment | undefined>;
|
|
24
|
-
onAllotmentReleased(): Promise<void>;
|
|
25
|
-
onLimitChanged(oldLimit: number, newLimit: number): void;
|
|
26
|
-
}
|
|
27
|
-
//# sourceMappingURL=LifoBlockingRejection.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LifoBlockingRejection.d.ts","sourceRoot":"","sources":["../../../src/limiter/allocation-unavailable-strategies/LifoBlockingRejection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,aAAa,EACb,4BAA4B,EAC7B,MAAM,kBAAkB,CAAC;AAM1B,MAAM,WAAW,4BAA4B,CAAC,QAAQ;IACpD;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IAEjC;;;;OAIG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,CAAC,CAAC,OAAO,EAAE,QAAQ,KAAK,MAAM,CAAC,GAAG,SAAS,CAAC;CACvE;AAED;;;;;GAKG;AACH,qBAAa,qBAAqB,CAChC,QAAQ,CACR,YAAW,4BAA4B,CAAC,QAAQ,CAAC;IACjD,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAqC;gBAElD,OAAO,GAAE,4BAA4B,CAAC,QAAQ,CAAM;IAQhE,sBAAsB,CACpB,OAAO,EAAE,QAAQ,EACjB,KAAK,EAAE,CAAC,OAAO,EAAE,QAAQ,KAAK,aAAa,EAC3C,MAAM,CAAC,EAAE,WAAW;IAKtB,mBAAmB;IAInB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI;CAGzD"}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import { LinkedWaiterQueue } from "../../utils/LinkedWaiterQueue.js";
|
|
2
|
-
import { BlockingBacklogRejection, } from "./BlockingBacklogRejection.js";
|
|
3
|
-
/**
|
|
4
|
-
* Rejection strategy that blocks the caller in a LIFO queue when the limit
|
|
5
|
-
* has been reached. This strategy favors availability over latency by
|
|
6
|
-
* processing the most recently blocked request first, keeping success
|
|
7
|
-
* latencies low and minimizing timeouts.
|
|
8
|
-
*/
|
|
9
|
-
export class LifoBlockingRejection {
|
|
10
|
-
delegate;
|
|
11
|
-
constructor(options = {}) {
|
|
12
|
-
this.delegate = new BlockingBacklogRejection({
|
|
13
|
-
backlogSize: options.backlogSize ?? 100,
|
|
14
|
-
backlogTimeout: options.backlogTimeout ?? 1_000,
|
|
15
|
-
queue: new LinkedWaiterQueue("front"),
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
onAllotmentUnavailable(context, retry, signal) {
|
|
19
|
-
return this.delegate.onAllotmentUnavailable(context, retry, signal);
|
|
20
|
-
}
|
|
21
|
-
onAllotmentReleased() {
|
|
22
|
-
return this.delegate.onAllotmentReleased();
|
|
23
|
-
}
|
|
24
|
-
onLimitChanged(oldLimit, newLimit) {
|
|
25
|
-
this.delegate.onLimitChanged(oldLimit, newLimit);
|
|
26
|
-
}
|
|
27
|
-
}
|