-import { isMainThread, MessageChannel, SHARE_ENV, Worker } from 'worker_threads'
+import {
+ isMainThread,
+ MessageChannel,
+ SHARE_ENV,
+ Worker
+} from 'node:worker_threads'
import type { Draft, MessageValue } from '../../utility-types'
import { AbstractPool } from '../abstract-pool'
import type { PoolOptions } from '../pool'
super(numberOfThreads, filePath, opts)
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
protected isMain (): boolean {
return isMainThread
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
public async destroyWorker (
worker: ThreadWorkerWithMessageChannel
): Promise<void> {
await worker.terminate()
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
protected sendToWorker (
worker: ThreadWorkerWithMessageChannel,
message: MessageValue<Data>
worker.postMessage(message)
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
public registerWorkerMessageListener<Message extends Data | Response>(
messageChannel: ThreadWorkerWithMessageChannel,
listener: (message: MessageValue<Message>) => void
messageChannel.port2?.on('message', listener)
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
protected createWorker (): ThreadWorkerWithMessageChannel {
return new Worker(this.filePath, {
env: SHARE_ENV
})
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
protected afterWorkerSetup (worker: ThreadWorkerWithMessageChannel): void {
const { port1, port2 } = new MessageChannel()
worker.postMessage({ parent: port1 }, [port1])
this.registerWorkerMessageListener(worker, super.workerListener())
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
public get type (): PoolType {
return PoolType.FIXED
}
- /** {@inheritDoc} */
+ /** @inheritDoc */
+ public get full (): boolean {
+ return this.workers.length === this.numberOfWorkers
+ }
+
+ /** @inheritDoc */
public get busy (): boolean {
- return this.internalGetBusyStatus()
+ return this.internalBusy()
}
}