repositories
/
poolifier.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
fix: ensure promise is awaited at pool destroy()
[poolifier.git]
/
src
/
pools
/
pool.ts
diff --git
a/src/pools/pool.ts
b/src/pools/pool.ts
index c6fbce43aba1d6a31d825a1eff80db8aae49ee12..dbbb5969ebd920022e31d64d156f087065aa9d12 100644
(file)
--- a/
src/pools/pool.ts
+++ b/
src/pools/pool.ts
@@
-1,3
+1,4
@@
+import EventEmitter from '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.
*/
@@
-33,7
+39,7
@@
export interface PoolOptions<Worker> {
/**
* Pool events emission.
*
/**
* 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> {
+ /**
+ * 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.
*
/**
* 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>
/**
* Shutdowns every current worker in this pool.
*/
/**
* Shutdowns every current worker in this pool.
*/
- destroy
():
Promise<void>
+ destroy
: () =>
Promise<void>
/**
* Sets the worker choice strategy in this pool.
*
/**
* Sets 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
}
}