repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
chore: v2.4.0-3
[poolifier.git]
/
src
/
pools
/
pool.ts
diff --git
a/src/pools/pool.ts
b/src/pools/pool.ts
index 8da89156ecef7869dd1d8a4e5fe5096a168e8280..8a5e505f4f2d23909db36ef3d66e987eee9e9afd 100644
(file)
--- a/
src/pools/pool.ts
+++ b/
src/pools/pool.ts
@@
-1,3
+1,4
@@
+import EventEmitter from 'node:events'
import type {
ErrorHandler,
ExitHandler,
import type {
ErrorHandler,
ExitHandler,
@@
-6,6
+7,11
@@
import type {
} from './pool-worker'
import type { WorkerChoiceStrategy } from './selection-strategies/selection-strategies-types'
} from './pool-worker'
import type { WorkerChoiceStrategy } from './selection-strategies/selection-strategies-types'
+/**
+ * Pool events emitter.
+ */
+export class PoolEmitter extends EventEmitter {}
+
/**
* Options for a poolifier pool.
*/
/**
* Options for a poolifier pool.
*/
@@
-27,13
+33,13
@@
export interface PoolOptions<Worker> {
*/
exitHandler?: ExitHandler<Worker>
/**
*/
exitHandler?: ExitHandler<Worker>
/**
- * The work choice strategy to use in this pool.
+ * The work
er
choice strategy to use in this pool.
*/
workerChoiceStrategy?: WorkerChoiceStrategy
/**
* Pool events emission.
*
*/
workerChoiceStrategy?: WorkerChoiceStrategy
/**
* Pool events emission.
*
- * @default true
+ * @default
Value
true
*/
enableEvents?: boolean
}
*/
enableEvents?: boolean
}
@@
-41,25
+47,33
@@
export interface PoolOptions<Worker> {
/**
* Contract definition for a poolifier pool.
*
/**
* Contract definition for a poolifier pool.
*
- * @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 response of execution. This can only be serializable data.
*/
export interface IPool<Data = unknown, Response = unknown> {
/**
*/
export interface IPool<Data = unknown, Response = unknown> {
/**
- * Perform the task specified in the constructor with the data parameter.
+ * Emitter on which events can be listened to.
+ *
+ * Events that can currently be listened to:
+ *
+ * - `'busy'`
+ */
+ readonly emitter?: PoolEmitter
+ /**
+ * Performs the task specified in the constructor with the data parameter.
*
*
- * @param data The input for the specified task. This can only be serializable data.
+ * @param data
-
The input for the specified task. This can only be serializable data.
* @returns Promise that will be resolved when the task is successfully completed.
*/
* @returns Promise that will be resolved when the task is successfully completed.
*/
- execute
(data: Data):
Promise<Response>
+ execute
: (data: Data) =>
Promise<Response>
/**
/**
- * Shut
down
every current worker in this pool.
+ * Shut
downs
every current worker in this pool.
*/
*/
- destroy
():
Promise<void>
+ destroy
: () =>
Promise<void>
/**
/**
- * Set the worker choice strategy in this pool.
+ * Set
s
the worker choice strategy in this pool.
*
*
- * @param workerChoiceStrategy The worker choice strategy.
+ * @param workerChoiceStrategy
-
The worker choice strategy.
*/
*/
- setWorkerChoiceStrategy
(workerChoiceStrategy: WorkerChoiceStrategy):
void
+ setWorkerChoiceStrategy
: (workerChoiceStrategy: WorkerChoiceStrategy) =>
void
}
}