repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: fix getWorkerTasksUsage() return type
[poolifier.git]
/
src
/
pools
/
thread
/
fixed.ts
diff --git
a/src/pools/thread/fixed.ts
b/src/pools/thread/fixed.ts
index a8161f6783f764831ef632bc4d48205419ab1850..7753d1d60cb21910a5f871338889023ef4de12c1 100644
(file)
--- a/
src/pools/thread/fixed.ts
+++ b/
src/pools/thread/fixed.ts
@@
-1,8
+1,13
@@
-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'
import type { Draft, MessageValue } from '../../utility-types'
import { AbstractPool } from '../abstract-pool'
import type { PoolOptions } from '../pool'
-import { PoolType } from '../pool
-internal
'
+import { PoolType } from '../pool'
/**
* A thread worker with message channels for communication between main thread and thread worker.
/**
* A thread worker with message channels for communication between main thread and thread worker.
@@
-16,8
+21,8
@@
export type ThreadWorkerWithMessageChannel = Worker & Draft<MessageChannel>
*
* This pool selects the threads in a round robin fashion.
*
*
* This pool selects the threads in a round robin fashion.
*
- * @t
emplate Data
Type of data sent to the worker. This can only be serializable data.
- * @t
emplate Response Type of response of execution
. This can only be serializable data.
+ * @t
ypeParam Data -
Type of data sent to the worker. This can only be serializable data.
+ * @t
ypeParam Response - Type of execution response
. This can only be serializable data.
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
* @since 0.0.1
*/
* @author [Alessandro Pio Ardizio](https://github.com/pioardi)
* @since 0.0.1
*/
@@
-28,9
+33,9
@@
export class FixedThreadPool<
/**
* Constructs a new poolifier fixed thread pool.
*
/**
* Constructs a new poolifier fixed thread pool.
*
- * @param numberOfThreads Number of threads for this pool.
- * @param filePath Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
- * @param opts Options for this fixed thread pool.
+ * @param numberOfThreads
-
Number of threads for this pool.
+ * @param filePath
-
Path to an implementation of a `ThreadWorker` file, which can be relative or absolute.
+ * @param opts
-
Options for this fixed thread pool.
*/
public constructor (
numberOfThreads: number,
*/
public constructor (
numberOfThreads: number,
@@
-46,7
+51,7
@@
export class FixedThreadPool<
}
/** @inheritDoc */
}
/** @inheritDoc */
- p
ublic
async destroyWorker (
+ p
rotected
async destroyWorker (
worker: ThreadWorkerWithMessageChannel
): Promise<void> {
this.sendToWorker(worker, { kill: 1 })
worker: ThreadWorkerWithMessageChannel
): Promise<void> {
this.sendToWorker(worker, { kill: 1 })
@@
-62,11
+67,11
@@
export class FixedThreadPool<
}
/** @inheritDoc */
}
/** @inheritDoc */
- p
ublic
registerWorkerMessageListener<Message extends Data | Response>(
-
messageChannel
: ThreadWorkerWithMessageChannel,
+ p
rotected
registerWorkerMessageListener<Message extends Data | Response>(
+
worker
: ThreadWorkerWithMessageChannel,
listener: (message: MessageValue<Message>) => void
): void {
listener: (message: MessageValue<Message>) => void
): void {
-
messageChannel
.port2?.on('message', listener)
+
worker
.port2?.on('message', listener)
}
/** @inheritDoc */
}
/** @inheritDoc */
@@
-92,7
+97,12
@@
export class FixedThreadPool<
}
/** @inheritDoc */
}
/** @inheritDoc */
- public get busy (): boolean {
- return this.internalGetBusyStatus()
+ protected get full (): boolean {
+ return this.workerNodes.length === this.numberOfWorkers
+ }
+
+ /** @inheritDoc */
+ protected get busy (): boolean {
+ return this.internalBusy()
}
}
}
}