in src/worker-pool.ts [42:65]
public format(files: string[]): Observable<IFormatResults> {
if (this.workers.length < this.options.concurrency) {
this.spawnWorker();
}
const target = this.workers[0];
const id = this.workIdCounter++;
target.active++;
this.sortWorkers();
return target.worker.pipe(
switchMap((worker) => {
worker.send({ type: MessageType.WorkerFiles, files, id });
return fromEvent<[WorkerMessage]>(worker, 'message');
}),
map(([m]) => m),
filter((m) => m.id === id),
take(1),
tap(() => {
target.active--;
this.sortWorkers();
}),
);
}