@zukhruf/pool 0.8.18 → 0.8.20
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 +271 -0
- package/dist/climbing.d.ts.map +1 -1
- package/dist/climbing.js +10 -2
- package/dist/climbing.js.map +1 -1
- package/dist/computer-store.d.ts +7 -0
- package/dist/computer-store.d.ts.map +1 -0
- package/dist/computer-store.js +29 -0
- package/dist/computer-store.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/pool.d.ts.map +1 -1
- package/dist/pool.js +20 -305
- package/dist/pool.js.map +1 -1
- package/dist/slots.d.ts +52 -0
- package/dist/slots.d.ts.map +1 -0
- package/dist/slots.js +339 -0
- package/dist/slots.js.map +1 -0
- package/dist/worker-kind.d.ts +19 -0
- package/dist/worker-kind.d.ts.map +1 -0
- package/dist/worker-kind.js +28 -0
- package/dist/worker-kind.js.map +1 -0
- package/package.json +4 -4
package/dist/pool.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import PQueue from 'p-queue';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
// exit, as Kubernetes restarts a container in CrashLoopBackOff (tuned by
|
|
5
|
-
// KEP-4603): 1 s, doubled for each early exit in a row, up to 60 s. A worker
|
|
6
|
-
// whose warm-up fails exits early too (ADR 0010). A worker that ran 10 minutes
|
|
7
|
-
// ends the back-off.
|
|
8
|
-
const backoff = { first: 1_000, most: 60_000, reset: 600_000 };
|
|
2
|
+
import { untilAborted } from '@zukhruf/async';
|
|
3
|
+
import { Slots } from "./slots.js";
|
|
9
4
|
// Lends workers to jobs, one job per worker at a time. The sizing decides how
|
|
10
5
|
// many workers run, the startup when they start, and the eviction when an
|
|
11
6
|
// idle worker closes. A job takes an idle worker first. A worker that exits is
|
|
@@ -14,85 +9,43 @@ const backoff = { first: 1_000, most: 60_000, reset: 600_000 };
|
|
|
14
9
|
// back-off when it exited early or its warm-up failed. The owner disposes the
|
|
15
10
|
// pool, which stops every worker.
|
|
16
11
|
export class Pool {
|
|
17
|
-
#create;
|
|
18
|
-
#startup;
|
|
19
|
-
#sizing;
|
|
20
|
-
#eviction;
|
|
21
12
|
#queue;
|
|
22
13
|
#slots;
|
|
23
|
-
#lent = new Set();
|
|
24
|
-
#workers = new Set();
|
|
25
|
-
#stopped = new AbortController();
|
|
26
|
-
#started = new Latch();
|
|
27
14
|
#clock;
|
|
28
|
-
// When the pool last changed how many workers it runs.
|
|
29
|
-
#resized;
|
|
30
15
|
constructor(options) {
|
|
31
16
|
this.#clock = options.clock;
|
|
32
|
-
this.#
|
|
33
|
-
this.#
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
index,
|
|
40
|
-
state: { kind: 'empty' },
|
|
41
|
-
early: 0,
|
|
42
|
-
}));
|
|
43
|
-
const outcomes = options.startup.eager
|
|
44
|
-
? this.#running().map((slot) => this.#spawn(slot))
|
|
45
|
-
: [];
|
|
46
|
-
Promise.all(outcomes.map((outcome) => settled(outcome))).then(() => this.#started.open({ status: 'fulfilled', value: undefined }), (reason) => this.#started.open({ status: 'rejected', reason }));
|
|
17
|
+
this.#queue = new PQueue({ concurrency: options.size.current });
|
|
18
|
+
this.#slots = new Slots({
|
|
19
|
+
...options,
|
|
20
|
+
resized: (current) => {
|
|
21
|
+
this.#queue.concurrency = current;
|
|
22
|
+
},
|
|
23
|
+
});
|
|
47
24
|
}
|
|
48
25
|
// Settles when the workers the startup starts with the pool are ready, and
|
|
49
26
|
// rejects when one of them fails to start.
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (outcome.status === 'rejected')
|
|
53
|
-
throw outcome.reason;
|
|
27
|
+
ready() {
|
|
28
|
+
return this.#slots.ready();
|
|
54
29
|
}
|
|
55
30
|
get stats() {
|
|
56
|
-
|
|
57
|
-
for (const slot of this.#slots) {
|
|
58
|
-
const lent = this.#lent.has(slot);
|
|
59
|
-
if (slot.state.kind === 'starting') {
|
|
60
|
-
stats.starting++;
|
|
61
|
-
if (lent)
|
|
62
|
-
stats.waiting++;
|
|
63
|
-
}
|
|
64
|
-
else if (slot.state.kind === 'ready') {
|
|
65
|
-
if (lent)
|
|
66
|
-
stats.lent++;
|
|
67
|
-
else
|
|
68
|
-
stats.idle++;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
return stats;
|
|
31
|
+
return this.#slots.stats(this.#queue.size);
|
|
72
32
|
}
|
|
73
33
|
// A job aborted while it runs kills its worker. A job aborted while its
|
|
74
34
|
// worker warms up leaves the warm-up running for the jobs after it.
|
|
75
35
|
use(job, signal) {
|
|
76
36
|
const stop = signal === undefined
|
|
77
|
-
? this.#stopped
|
|
78
|
-
: AbortSignal.any([this.#stopped
|
|
37
|
+
? this.#slots.stopped
|
|
38
|
+
: AbortSignal.any([this.#slots.stopped, signal]);
|
|
79
39
|
if (stop.aborted)
|
|
80
40
|
return Promise.reject(stop.reason);
|
|
81
41
|
// The queue does not take the signal: on abort it would free the slot
|
|
82
42
|
// while the job still holds its worker.
|
|
83
43
|
return this.#queue.add(async () => {
|
|
84
44
|
stop.throwIfAborted();
|
|
85
|
-
const slot = this.#
|
|
86
|
-
this.#lent.add(slot);
|
|
87
|
-
// A job takes the worker before its eviction lets it go.
|
|
88
|
-
if (slot.state.kind === 'ready')
|
|
89
|
-
slot.state.idle.abort();
|
|
45
|
+
const slot = this.#slots.lend();
|
|
90
46
|
try {
|
|
91
|
-
const worker = await untilAborted(this.#borrow(slot), stop);
|
|
92
|
-
const kill = () =>
|
|
93
|
-
worker.kill();
|
|
94
|
-
this.#lose(slot, worker);
|
|
95
|
-
};
|
|
47
|
+
const worker = await untilAborted(this.#slots.borrow(slot), stop);
|
|
48
|
+
const kill = () => this.#slots.kill(slot, worker);
|
|
96
49
|
stop.addEventListener('abort', kill, { once: true });
|
|
97
50
|
const started = this.#clock.performance.now();
|
|
98
51
|
try {
|
|
@@ -107,255 +60,17 @@ export class Pool {
|
|
|
107
60
|
finally {
|
|
108
61
|
stop.removeEventListener('abort', kill);
|
|
109
62
|
if (!stop.aborted)
|
|
110
|
-
this.#record(started);
|
|
63
|
+
this.#slots.record(started, this.#queue.size > 0);
|
|
111
64
|
}
|
|
112
65
|
}
|
|
113
66
|
finally {
|
|
114
|
-
this.#
|
|
115
|
-
const state = slot.state;
|
|
116
|
-
if (slot.index >= this.#sizing.kept)
|
|
117
|
-
this.#retire(slot);
|
|
118
|
-
else if (state.kind === 'ready')
|
|
119
|
-
this.#rest(slot, state.worker, state.since);
|
|
120
|
-
else if (state.kind === 'lost')
|
|
121
|
-
this.#replace(slot, state.worker, state.since);
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
#running() {
|
|
126
|
-
return this.#slots.slice(0, this.#sizing.current);
|
|
127
|
-
}
|
|
128
|
-
// The slot a job takes, the lowest of its kind: an idle worker, else a
|
|
129
|
-
// worker that starts, else an empty slot or one whose worker ended, else a
|
|
130
|
-
// back-off. Jobs stay on the low slots, so the high ones stay idle until
|
|
131
|
-
// their eviction lets them go. This is the reason Commons Pool lends the
|
|
132
|
-
// object returned last (POOL-86) and Go's database/sql reuses the connection
|
|
133
|
-
// idle for the shortest time (sql.go:1336-1341).
|
|
134
|
-
#pick() {
|
|
135
|
-
const free = this.#running().filter((slot) => !this.#lent.has(slot));
|
|
136
|
-
return (free.find(({ state }) => state.kind === 'ready') ??
|
|
137
|
-
free.find(({ state }) => state.kind === 'starting') ??
|
|
138
|
-
free.find(({ state }) => state.kind === 'empty' || state.kind === 'lost') ??
|
|
139
|
-
free.find(({ state }) => state.kind === 'backoff'));
|
|
140
|
-
}
|
|
141
|
-
async #borrow(slot) {
|
|
142
|
-
const state = slot.state;
|
|
143
|
-
if (state.kind === 'ready')
|
|
144
|
-
return state.worker;
|
|
145
|
-
if (state.kind === 'lost') {
|
|
146
|
-
this.#enter(slot, { kind: 'empty' });
|
|
147
|
-
void this.#close(state.worker);
|
|
148
|
-
}
|
|
149
|
-
// A job does not wait out a back-off: its worker starts now, and the start
|
|
150
|
-
// ends the wait of the back-off.
|
|
151
|
-
const worker = await settled(state.kind === 'starting' ? state.outcome : this.#spawn(slot));
|
|
152
|
-
const now = slot.state;
|
|
153
|
-
if (now.kind === 'ready' && now.worker === worker)
|
|
154
|
-
return worker;
|
|
155
|
-
// The worker exited between its start and this borrow.
|
|
156
|
-
return this.#borrow(slot);
|
|
157
|
-
}
|
|
158
|
-
// A job measures how many workers pay only if, since it started, the pool
|
|
159
|
-
// ran the same number of workers and each was ready, and another job waited
|
|
160
|
-
// when it finished.
|
|
161
|
-
#record(started) {
|
|
162
|
-
const steady = this.#steady();
|
|
163
|
-
this.#sizing.record({
|
|
164
|
-
started,
|
|
165
|
-
finished: this.#clock.performance.now(),
|
|
166
|
-
measurable: steady !== undefined && started >= steady && this.#queue.size > 0,
|
|
167
|
-
});
|
|
168
|
-
for (const slot of this.#slots.slice(this.#sizing.kept))
|
|
169
|
-
this.#retire(slot);
|
|
170
|
-
if (this.#sizing.current === this.#queue.concurrency)
|
|
171
|
-
return;
|
|
172
|
-
this.#queue.concurrency = this.#sizing.current;
|
|
173
|
-
this.#resized = this.#clock.performance.now();
|
|
174
|
-
// An idle worker waits for its eviction only while the pool runs its slot.
|
|
175
|
-
for (const slot of this.#slots.slice(0, this.#sizing.kept)) {
|
|
176
|
-
const state = slot.state;
|
|
177
|
-
if (state.kind === 'ready' &&
|
|
178
|
-
!this.#lent.has(slot) &&
|
|
179
|
-
state.idle.signal.aborted === slot.index < this.#sizing.current)
|
|
180
|
-
this.#rest(slot, state.worker, state.since);
|
|
181
|
-
}
|
|
182
|
-
for (const slot of this.#running())
|
|
183
|
-
if (slot.state.kind === 'empty')
|
|
184
|
-
this.#spawn(slot);
|
|
185
|
-
}
|
|
186
|
-
// Since when every slot the pool runs has had a ready worker, if they have.
|
|
187
|
-
#steady() {
|
|
188
|
-
let since = this.#resized;
|
|
189
|
-
for (const { state } of this.#running()) {
|
|
190
|
-
if (state.kind !== 'ready')
|
|
191
|
-
return undefined;
|
|
192
|
-
since = Math.max(since, state.since);
|
|
193
|
-
}
|
|
194
|
-
return since;
|
|
195
|
-
}
|
|
196
|
-
#spawn(slot) {
|
|
197
|
-
const outcome = new Latch();
|
|
198
|
-
this.#enter(slot, { kind: 'starting', outcome });
|
|
199
|
-
const turn = Promise.withResolvers();
|
|
200
|
-
this.#startup
|
|
201
|
-
.turn(turn.promise)
|
|
202
|
-
.then(async () => {
|
|
203
|
-
this.#stopped.signal.throwIfAborted();
|
|
204
|
-
const worker = this.#create();
|
|
205
|
-
this.#workers.add(worker);
|
|
206
|
-
try {
|
|
207
|
-
await worker.ready?.();
|
|
208
|
-
return worker;
|
|
67
|
+
this.#slots.release(slot);
|
|
209
68
|
}
|
|
210
|
-
catch (error) {
|
|
211
|
-
worker.kill();
|
|
212
|
-
await this.#close(worker);
|
|
213
|
-
throw error;
|
|
214
|
-
}
|
|
215
|
-
})
|
|
216
|
-
.then((worker) => {
|
|
217
|
-
if (slot.state.kind === 'starting' && slot.state.outcome === outcome)
|
|
218
|
-
this.#rest(slot, worker, this.#clock.performance.now());
|
|
219
|
-
outcome.open({ status: 'fulfilled', value: worker });
|
|
220
|
-
turn.resolve();
|
|
221
|
-
void worker.exited().then(() => this.#ended(slot, worker));
|
|
222
|
-
}, (reason) => {
|
|
223
|
-
if (slot.state.kind === 'starting' &&
|
|
224
|
-
slot.state.outcome === outcome) {
|
|
225
|
-
this.#enter(slot, { kind: 'empty' });
|
|
226
|
-
// A failed warm-up is an early exit, whoever started the worker,
|
|
227
|
-
// as HikariCP tries a failed create again (ADR 0010).
|
|
228
|
-
if (this.#startup.eager && !this.#stopped.signal.aborted) {
|
|
229
|
-
slot.early++;
|
|
230
|
-
this.#restart(slot);
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
outcome.open({ status: 'rejected', reason });
|
|
234
|
-
turn.resolve();
|
|
235
69
|
});
|
|
236
|
-
return outcome;
|
|
237
|
-
}
|
|
238
|
-
// Every change of a slot's state comes here, so a ready worker that leaves
|
|
239
|
-
// its slot ends its idle wait, and a slot that leaves its back-off ends the
|
|
240
|
-
// wait of the back-off.
|
|
241
|
-
#enter(slot, next) {
|
|
242
|
-
const state = slot.state;
|
|
243
|
-
if (state.kind === 'ready')
|
|
244
|
-
state.idle.abort();
|
|
245
|
-
else if (state.kind === 'backoff')
|
|
246
|
-
state.wait.abort();
|
|
247
|
-
slot.state = next;
|
|
248
|
-
}
|
|
249
|
-
// A worker becomes idle in a slot. Its eviction may let it go only while
|
|
250
|
-
// no job has it and the pool runs its slot: a slot the sizing keeps but does
|
|
251
|
-
// not run has the worker the sizing tries (ADR 0002).
|
|
252
|
-
#rest(slot, worker, since) {
|
|
253
|
-
const state = {
|
|
254
|
-
kind: 'ready',
|
|
255
|
-
worker,
|
|
256
|
-
since,
|
|
257
|
-
idle: new AbortController(),
|
|
258
|
-
};
|
|
259
|
-
this.#enter(slot, state);
|
|
260
|
-
if (this.#lent.has(slot) || slot.index >= this.#sizing.current) {
|
|
261
|
-
state.idle.abort();
|
|
262
|
-
return;
|
|
263
|
-
}
|
|
264
|
-
this.#eviction.idle(AbortSignal.any([state.idle.signal, this.#stopped.signal]), () => this.#evict(slot, state), this.#clock);
|
|
265
|
-
}
|
|
266
|
-
// Closes an idle worker that its eviction let go. The slot is empty before
|
|
267
|
-
// the worker closes, so its exit starts no back-off and no replacement. A
|
|
268
|
-
// worker that ran 10 minutes ends the back-off, as at an exit.
|
|
269
|
-
#evict(slot, state) {
|
|
270
|
-
if (slot.state !== state ||
|
|
271
|
-
this.#lent.has(slot) ||
|
|
272
|
-
slot.index >= this.#sizing.current ||
|
|
273
|
-
this.#stopped.signal.aborted)
|
|
274
|
-
return;
|
|
275
|
-
if (this.#clock.performance.now() - state.since >= backoff.reset)
|
|
276
|
-
slot.early = 0;
|
|
277
|
-
this.#retire(slot);
|
|
278
|
-
}
|
|
279
|
-
// The pool killed the worker of a slot: no job may borrow it any more.
|
|
280
|
-
#lose(slot, worker) {
|
|
281
|
-
const state = slot.state;
|
|
282
|
-
if (state.kind === 'ready' && state.worker === worker)
|
|
283
|
-
this.#enter(slot, { kind: 'lost', worker, since: state.since });
|
|
284
|
-
}
|
|
285
|
-
#ended(slot, worker) {
|
|
286
|
-
const state = slot.state;
|
|
287
|
-
if ((state.kind !== 'ready' && state.kind !== 'lost') ||
|
|
288
|
-
state.worker !== worker)
|
|
289
|
-
return;
|
|
290
|
-
this.#enter(slot, { kind: 'lost', worker, since: state.since });
|
|
291
|
-
if (!this.#lent.has(slot))
|
|
292
|
-
this.#replace(slot, worker, state.since);
|
|
293
|
-
}
|
|
294
|
-
// An eager pool closes the worker of a lost slot that no job has, and
|
|
295
|
-
// starts the next one.
|
|
296
|
-
#replace(slot, worker, since) {
|
|
297
|
-
if (this.#stopped.signal.aborted || !this.#startup.eager)
|
|
298
|
-
return;
|
|
299
|
-
this.#enter(slot, { kind: 'empty' });
|
|
300
|
-
void this.#close(worker);
|
|
301
|
-
slot.early =
|
|
302
|
-
this.#clock.performance.now() - since < backoff.reset
|
|
303
|
-
? slot.early + 1
|
|
304
|
-
: 0;
|
|
305
|
-
this.#restart(slot);
|
|
306
|
-
}
|
|
307
|
-
// Starts the next worker of an empty slot that the pool runs: at once when
|
|
308
|
-
// no early exit came before, else after the back-off. A job that takes the
|
|
309
|
-
// slot, the sizing that stops keeping it, or the disposal ends the wait.
|
|
310
|
-
#restart(slot) {
|
|
311
|
-
if (slot.index >= this.#sizing.current)
|
|
312
|
-
return;
|
|
313
|
-
if (slot.early === 0) {
|
|
314
|
-
this.#spawn(slot);
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
const state = { kind: 'backoff', wait: new AbortController() };
|
|
318
|
-
this.#enter(slot, state);
|
|
319
|
-
delay(Math.min(backoff.first * 2 ** (slot.early - 1), backoff.most), {
|
|
320
|
-
clock: this.#clock,
|
|
321
|
-
signal: AbortSignal.any([state.wait.signal, this.#stopped.signal]),
|
|
322
|
-
}).then(() => {
|
|
323
|
-
if (slot.state !== state)
|
|
324
|
-
return;
|
|
325
|
-
this.#enter(slot, { kind: 'empty' });
|
|
326
|
-
if (slot.index < this.#sizing.current)
|
|
327
|
-
this.#spawn(slot);
|
|
328
|
-
}, () => undefined);
|
|
329
|
-
}
|
|
330
|
-
// Closes the worker of a slot the pool no longer keeps, once its job ends.
|
|
331
|
-
#retire(slot) {
|
|
332
|
-
if (this.#lent.has(slot))
|
|
333
|
-
return;
|
|
334
|
-
const state = slot.state;
|
|
335
|
-
this.#enter(slot, { kind: 'empty' });
|
|
336
|
-
if (state.kind === 'ready' || state.kind === 'lost')
|
|
337
|
-
void this.#close(state.worker);
|
|
338
|
-
else if (state.kind === 'starting')
|
|
339
|
-
void settled(state.outcome).then((worker) => this.#close(worker), () => undefined);
|
|
340
|
-
}
|
|
341
|
-
async #close(worker) {
|
|
342
|
-
await worker.close();
|
|
343
|
-
this.#workers.delete(worker);
|
|
344
70
|
}
|
|
345
71
|
async [Symbol.asyncDispose]() {
|
|
346
|
-
|
|
347
|
-
this.#stopped.abort();
|
|
348
|
-
for (const worker of this.#workers)
|
|
349
|
-
worker.kill();
|
|
350
|
-
await Promise.all([...this.#workers].map((worker) => worker.close()));
|
|
72
|
+
await this.#slots[Symbol.asyncDispose]();
|
|
351
73
|
await this.#queue.onIdle();
|
|
352
74
|
}
|
|
353
75
|
}
|
|
354
|
-
// The worker a creation gave, or its failure.
|
|
355
|
-
async function settled(outcome) {
|
|
356
|
-
const result = await outcome.wait();
|
|
357
|
-
if (result.status === 'rejected')
|
|
358
|
-
throw result.reason;
|
|
359
|
-
return result.value;
|
|
360
|
-
}
|
|
361
76
|
//# sourceMappingURL=pool.js.map
|
package/dist/pool.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"pool.js","sourceRoot":"","sources":["../src/pool.ts"],"names":[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c,EAAE,CAAC;oBACtB,OAAO,MAAM,CAAC;gBAChB,CAAC;gBAAC,OAAO,KAAK,EAAE,CAAC;oBACf,IAAI,CAAC,cAAc,EAAE,CAAC;oBACtB,MAAM,KAAK,CAAC;gBACd,CAAC;wBAAS,CAAC;oBACT,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;oBACxC,IAAI,CAAC,IAAI,CAAC,OAAO;wBAAE,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,CAAC,CAAC,CAAC;gBACvE,CAAC;YACH,CAAC;oBAAS,CAAC;gBACT,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;YAC5B,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,CAAC,MAAM,CAAC,YAAY,CAAC;QACzB,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,CAAC;QACzC,MAAM,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC7B,CAAC;CACF"}
|
package/dist/slots.d.ts
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { type Clock, Latch } from '@zukhruf/async';
|
|
2
|
+
import type { Eviction } from './eviction.ts';
|
|
3
|
+
import type { PoolStats } from './pool-stats.ts';
|
|
4
|
+
import type { Sizing } from './sizing.ts';
|
|
5
|
+
import type { Startup } from './startup.ts';
|
|
6
|
+
import type { Worker } from './worker.ts';
|
|
7
|
+
interface Ready<T> {
|
|
8
|
+
readonly kind: 'ready';
|
|
9
|
+
readonly worker: T;
|
|
10
|
+
readonly since: number;
|
|
11
|
+
readonly idle: AbortController;
|
|
12
|
+
}
|
|
13
|
+
type State<T> = {
|
|
14
|
+
readonly kind: 'empty';
|
|
15
|
+
} | {
|
|
16
|
+
readonly kind: 'starting';
|
|
17
|
+
readonly outcome: Latch<PromiseSettledResult<T>>;
|
|
18
|
+
} | Ready<T> | {
|
|
19
|
+
readonly kind: 'lost';
|
|
20
|
+
readonly worker: T;
|
|
21
|
+
readonly since: number;
|
|
22
|
+
} | {
|
|
23
|
+
readonly kind: 'backoff';
|
|
24
|
+
readonly wait: AbortController;
|
|
25
|
+
};
|
|
26
|
+
export interface Slot<T> {
|
|
27
|
+
readonly index: number;
|
|
28
|
+
state: State<T>;
|
|
29
|
+
early: number;
|
|
30
|
+
}
|
|
31
|
+
export declare class Slots<T extends Worker> implements AsyncDisposable {
|
|
32
|
+
#private;
|
|
33
|
+
constructor(options: {
|
|
34
|
+
size: Sizing;
|
|
35
|
+
startup: Startup;
|
|
36
|
+
eviction: Eviction;
|
|
37
|
+
create: () => T;
|
|
38
|
+
clock: Clock;
|
|
39
|
+
resized: (current: number) => void;
|
|
40
|
+
});
|
|
41
|
+
get stopped(): AbortSignal;
|
|
42
|
+
ready(): Promise<void>;
|
|
43
|
+
stats(queued: number): PoolStats;
|
|
44
|
+
lend(): Slot<T>;
|
|
45
|
+
borrow(slot: Slot<T>): Promise<T>;
|
|
46
|
+
kill(slot: Slot<T>, worker: T): void;
|
|
47
|
+
record(started: number, waited: boolean): void;
|
|
48
|
+
release(slot: Slot<T>): void;
|
|
49
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
52
|
+
//# sourceMappingURL=slots.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"slots.d.ts","sourceRoot":"","sources":["../src/slots.ts"],"names":[],"mappings":"AAAA,OAAO,EAAW,KAAK,KAAK,EAAE,KAAK,EAAS,MAAM,gBAAgB,CAAC;AAEnE,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAC9C,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO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