1 import { ThreadWorker
} from
'poolifier'
5 type ThreadWorkerResponse
8 const factorial
: (n
: number) => number = n
=> {
12 return factorial(n
- 1) * n
15 class RequestHandlerWorker
<
16 Data
extends ThreadWorkerData
<DataPayload
>,
17 Response
extends ThreadWorkerResponse
<DataPayload
>
18 > extends ThreadWorker
<Data
, Response
> {
19 public constructor () {
21 echo
: (workerData
?: Data
) => {
22 return workerData
as unknown
as Response
24 factorial
: (workerData
?: Data
) => {
26 data
: { number: factorial(workerData
?.data
?.number as number) }
27 } as unknown
as Response
33 export const requestHandlerWorker
= new RequestHandlerWorker
<
34 ThreadWorkerData
<DataPayload
>,
35 ThreadWorkerResponse
<DataPayload
>