repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
refactor: incrementation consistency
[poolifier.git]
/
src
/
worker
/
cluster-worker.ts
diff --git
a/src/worker/cluster-worker.ts
b/src/worker/cluster-worker.ts
index efc17acf0b9205f05ff621e399b448af2cfbbb47..c43e7f75a7586d2b2a9fa6633eea7da6e44697bf 100644
(file)
--- a/
src/worker/cluster-worker.ts
+++ b/
src/worker/cluster-worker.ts
@@
-1,4
+1,4
@@
-import cluster from 'node:cluster'
+import cluster
, { type Worker }
from 'node:cluster'
import type { MessageValue } from '../utility-types'
import { AbstractWorker } from './abstract-worker'
import type { WorkerOptions } from './worker-options'
import type { MessageValue } from '../utility-types'
import { AbstractWorker } from './abstract-worker'
import type { WorkerOptions } from './worker-options'
@@
-21,7
+21,7
@@
import type { TaskFunctions, WorkerFunction } from './worker-functions'
export class ClusterWorker<
Data = unknown,
Response = unknown
export class ClusterWorker<
Data = unknown,
Response = unknown
-> extends AbstractWorker<
NodeJS.Process
, Data, Response> {
+> extends AbstractWorker<
Worker
, Data, Response> {
/**
* Constructs a new poolifier cluster worker.
*
/**
* Constructs a new poolifier cluster worker.
*
@@
-38,22
+38,18
@@
export class ClusterWorker<
'worker-cluster-pool:poolifier',
cluster.isPrimary,
taskFunctions,
'worker-cluster-pool:poolifier',
cluster.isPrimary,
taskFunctions,
-
process
,
+
cluster.worker as Worker
,
opts
)
}
/** @inheritDoc */
opts
)
}
/** @inheritDoc */
- protected sendToMainWorker (message: MessageValue<Response>): void {
- const mainWorker = this.getMainWorker()
- if (mainWorker.send == null) {
- throw new Error('Main worker does not support IPC communication')
- }
- mainWorker.send(message)
+ protected get id (): number {
+ return this.getMainWorker().id
}
/** @inheritDoc */
}
/** @inheritDoc */
- protected
handleError (e: Error | string): string
{
- return e instanceof Error ? e.message : e
+ protected
sendToMainWorker (message: MessageValue<Response>): void
{
+ this.getMainWorker().send(message)
}
}
}
}