chore(integration): snapshot local main worktree
This commit is contained in:
@@ -142,6 +142,7 @@ export interface PiWorkerPoolOptions {
|
||||
openWorker(input: PiWorkerOpenInput): Promise<PiWorkerOpenResult>;
|
||||
maxRunning?: number;
|
||||
maxIdle?: number;
|
||||
processMode?: 'dedicated' | 'shared';
|
||||
processBudget?: PiProcessBudget;
|
||||
revisionCoordinator?: PiManagedInputRevisionCoordinator;
|
||||
now?: () => number;
|
||||
@@ -258,6 +259,7 @@ export class PiWorkerPool {
|
||||
private readonly openWorker: PiWorkerPoolOptions['openWorker'];
|
||||
private readonly maxRunning: number;
|
||||
private readonly maxIdle: number;
|
||||
private readonly processMode: 'dedicated' | 'shared';
|
||||
private readonly processBudget: PiProcessBudget;
|
||||
private readonly revisions: PiManagedInputRevisionCoordinator;
|
||||
private readonly now: () => number;
|
||||
@@ -290,6 +292,7 @@ export class PiWorkerPool {
|
||||
this.openWorker = options.openWorker;
|
||||
this.maxRunning = options.maxRunning ?? 4;
|
||||
this.maxIdle = options.maxIdle ?? 4;
|
||||
this.processMode = options.processMode ?? 'dedicated';
|
||||
this.processBudget = options.processBudget ?? new PiProcessBudget();
|
||||
this.revisions = options.revisionCoordinator ?? new PiManagedInputRevisionCoordinator();
|
||||
this.now = options.now ?? Date.now;
|
||||
@@ -979,7 +982,7 @@ export class PiWorkerPool {
|
||||
if (record.processStopFlight) await record.processStopFlight;
|
||||
else await record.worker.stop(reason);
|
||||
let lease = record.processLease;
|
||||
if (!lease) lease = await this.processBudget.acquire(this.shutdownController.signal);
|
||||
if (!lease) lease = await this.acquireWorkerLease();
|
||||
if (this.shuttingDown) {
|
||||
lease.release();
|
||||
if (record.processLease === lease) record.processLease = null;
|
||||
@@ -1232,7 +1235,7 @@ export class PiWorkerPool {
|
||||
private async openWithLease(
|
||||
input: PiWorkerOpenInput,
|
||||
): Promise<{ opened: PiWorkerOpenResult; lease: PiProcessLease }> {
|
||||
const lease = await this.processBudget.acquire(this.shutdownController.signal);
|
||||
const lease = await this.acquireWorkerLease();
|
||||
if (this.shuttingDown) {
|
||||
lease.release();
|
||||
throw new Error('Pi worker pool is shutting down');
|
||||
@@ -1251,6 +1254,13 @@ export class PiWorkerPool {
|
||||
}
|
||||
}
|
||||
|
||||
private acquireWorkerLease(): Promise<PiProcessLease> {
|
||||
if (this.processMode === 'shared') {
|
||||
return Promise.resolve({ release: () => undefined });
|
||||
}
|
||||
return this.processBudget.acquire(this.shutdownController.signal);
|
||||
}
|
||||
|
||||
private async stopAndRelease(record: WorkerRecord, reason: PiWorkerStopReason): Promise<void> {
|
||||
try {
|
||||
await record.worker.stop(reason);
|
||||
|
||||
Reference in New Issue
Block a user