feat: add Pi conversation worker pool
This commit is contained in:
@@ -177,6 +177,7 @@ export class PiWorkerProcess {
|
||||
private stopping = false;
|
||||
private stopPromise: Promise<PiWorkerStopResult> | null = null;
|
||||
private exitResult: Promise<{ code: number | null; signal: NodeJS.Signals | null }> | null = null;
|
||||
private readonly invalidationListeners = new Set<(error: PiProcessError) => void>();
|
||||
|
||||
constructor(options: PiWorkerProcessOptions) {
|
||||
this.options = options;
|
||||
@@ -314,6 +315,11 @@ export class PiWorkerProcess {
|
||||
return this.rpc.subscribe(listener);
|
||||
}
|
||||
|
||||
subscribeInvalidation(listener: (error: PiProcessError) => void): () => void {
|
||||
this.invalidationListeners.add(listener);
|
||||
return () => this.invalidationListeners.delete(listener);
|
||||
}
|
||||
|
||||
stop(): Promise<PiWorkerStopResult> {
|
||||
if (!this.stopPromise) this.stopPromise = this.performStop();
|
||||
return this.stopPromise;
|
||||
@@ -345,6 +351,15 @@ export class PiWorkerProcess {
|
||||
this.invalidation = error;
|
||||
this.rpc?.invalidate(error);
|
||||
this.generationValue += 1;
|
||||
for (const listener of this.invalidationListeners) {
|
||||
try {
|
||||
listener(error);
|
||||
} catch (listenerError) {
|
||||
this.appendDiagnostic(
|
||||
`[invalidation-listener] ${listenerError instanceof Error ? listenerError.message : String(listenerError)}\n`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private appendDiagnostic(source: string): void {
|
||||
|
||||
Reference in New Issue
Block a user