`worker${extname(fileURLToPath(import.meta.url))}`
)
-export const fixedPool = new FixedThreadPool<MyData, Promise<MyResponse>>(
+export const fixedPool = new FixedThreadPool<MyData, MyResponse>(
availableParallelism(),
workerFile,
{
}
)
-export const dynamicPool = new DynamicThreadPool<MyData, Promise<MyResponse>>(
+export const dynamicPool = new DynamicThreadPool<MyData, MyResponse>(
Math.floor(availableParallelism() / 2),
availableParallelism(),
workerFile,
export interface MyResponse {
message: string
- data: MyData
+ data?: MyData
}
-class MyThreadWorker extends ThreadWorker<MyData, Promise<MyResponse>> {
+class MyThreadWorker extends ThreadWorker<MyData, MyResponse> {
constructor () {
- super(async (data: MyData) => await this.process(data), {
+ super(async (data?: MyData) => await this.process(data), {
maxInactiveTime: 60000
})
}
- private async process (data: MyData): Promise<MyResponse> {
+ private async process (data?: MyData): Promise<MyResponse> {
return await new Promise(resolve => {
setTimeout(() => {
resolve({ message: 'Hello from Worker :)', data })