From fab6d3b5750d884b29e5e7057628a06d88d0df8a Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Sun, 23 Apr 2023 00:29:53 +0000
Subject: [PATCH] chore: generate documentation
---
docs/assets/main.js | 4 +-
docs/assets/search.js | 2 +-
docs/assets/style.css | 85 ++++++----
docs/classes/AbstractPool.html | 158 +++++++++---------
docs/classes/AbstractWorker.html | 93 +++++------
docs/classes/CircularArray.html | 118 +++++++------
docs/classes/ClusterWorker.html | 89 +++++-----
docs/classes/DynamicClusterPool.html | 105 ++++++------
docs/classes/DynamicThreadPool.html | 105 ++++++------
docs/classes/FixedClusterPool.html | 103 ++++++------
docs/classes/FixedThreadPool.html | 103 ++++++------
docs/classes/PoolEmitter.html | 101 ++++++-----
docs/classes/ThreadWorker.html | 89 +++++-----
docs/classes/WorkerChoiceStrategyContext.html | 41 +++--
docs/enums/PoolType.html | 6 +-
docs/interfaces/ClusterPoolOptions.html | 24 +--
docs/interfaces/IPool.html | 29 ++--
docs/interfaces/IWorker.html | 6 +-
docs/interfaces/IWorkerChoiceStrategy.html | 12 +-
docs/interfaces/MessageValue.html | 18 +-
docs/interfaces/PoolOptions.html | 24 +--
docs/interfaces/PromiseResponseWrapper.html | 12 +-
docs/interfaces/RequiredStatistics.html | 8 +-
docs/interfaces/Task.html | 10 +-
docs/interfaces/TasksQueueOptions.html | 4 +-
docs/interfaces/TasksUsage.html | 16 +-
.../WorkerChoiceStrategyOptions.html | 4 +-
docs/interfaces/WorkerNode.html | 12 +-
docs/interfaces/WorkerOptions.html | 8 +-
docs/types/Draft.html | 6 +-
docs/types/ErrorHandler.html | 6 +-
docs/types/ExitHandler.html | 6 +-
docs/types/KillBehavior.html | 2 +-
docs/types/MessageHandler.html | 6 +-
docs/types/OnlineHandler.html | 6 +-
docs/types/PoolEvent.html | 2 +-
.../types/ThreadWorkerWithMessageChannel.html | 2 +-
docs/types/WorkerAsyncFunction.html | 6 +-
docs/types/WorkerChoiceStrategy.html | 2 +-
docs/types/WorkerFunction.html | 6 +-
docs/types/WorkerSyncFunction.html | 6 +-
docs/variables/KillBehaviors.html | 2 +-
docs/variables/PoolEvents.html | 2 +-
docs/variables/WorkerChoiceStrategies.html | 2 +-
44 files changed, 719 insertions(+), 732 deletions(-)
diff --git a/docs/assets/main.js b/docs/assets/main.js
index 932e185d..5e525428 100644
--- a/docs/assets/main.js
+++ b/docs/assets/main.js
@@ -1,7 +1,7 @@
"use strict";
"use strict";(()=>{var be=Object.create;var re=Object.defineProperty;var Se=Object.getOwnPropertyDescriptor;var we=Object.getOwnPropertyNames;var Te=Object.getPrototypeOf,ke=Object.prototype.hasOwnProperty;var Qe=(t,e)=>()=>(e||t((e={exports:{}}).exports,e),e.exports);var Pe=(t,e,r,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of we(e))!ke.call(t,i)&&i!==r&&re(t,i,{get:()=>e[i],enumerable:!(n=Se(e,i))||n.enumerable});return t};var Ie=(t,e,r)=>(r=t!=null?be(Te(t)):{},Pe(e||!t||!t.__esModule?re(r,"default",{value:t,enumerable:!0}):r,t));var ae=Qe((se,oe)=>{(function(){var t=function(e){var r=new t.Builder;return r.pipeline.add(t.trimmer,t.stopWordFilter,t.stemmer),r.searchPipeline.add(t.stemmer),e.call(r,r),r.build()};t.version="2.3.9";t.utils={},t.utils.warn=function(e){return function(r){e.console&&console.warn&&console.warn(r)}}(this),t.utils.asString=function(e){return e==null?"":e.toString()},t.utils.clone=function(e){if(e==null)return e;for(var r=Object.create(null),n=Object.keys(e),i=0;i Type of worker which manages this pool. Constructs a new poolifier pool. Path to the worker file. Number of workers that this pool should manage. Options for the pool. When we receive a message from the worker, we get a map entry with the promise resolve/reject bound to the message id. Default to a round robin algorithm.=e;r--){var n=this.uncheckedNodes[r],i=n.child.toString();i in this.minimizedNodes?n.parent.edges[n.char]=this.minimizedNodes[i]:(n.child._str=i,this.minimizedNodes[i]=n.child),this.uncheckedNodes.pop()}};t.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},t.Index.prototype.search=function(e){return this.query(function(r){var n=new t.QueryParser(e,r);n.parse()})},t.Index.prototype.query=function(e){for(var r=new t.Query(this.fields),n=Object.create(null),i=Object.create(null),s=Object.create(null),o=Object.create(null),a=Object.create(null),l=0;l=e;r--){var n=this.uncheckedNodes[r],i=n.child.toString();i in this.minimizedNodes?n.parent.edges[n.char]=this.minimizedNodes[i]:(n.child._str=i,this.minimizedNodes[i]=n.child),this.uncheckedNodes.pop()}};t.Index=function(e){this.invertedIndex=e.invertedIndex,this.fieldVectors=e.fieldVectors,this.tokenSet=e.tokenSet,this.fields=e.fields,this.pipeline=e.pipeline},t.Index.prototype.search=function(e){return this.query(function(r){var n=new t.QueryParser(e,r);n.parse()})},t.Index.prototype.query=function(e){for(var r=new t.Query(this.fields),n=Object.create(null),i=Object.create(null),s=Object.create(null),o=Object.create(null),a=Object.create(null),l=0;lType Parameters
-
+
Worker extends IWorker
+
@@ -124,9 +124,9 @@
Type Parameters
-
+
Worker extends IWorker<Worker>
Returns AbstractPool<Worker, Data, Response>
Properties
Readonly
fileReadonly
numberReadonly
opts
@@ -198,7 +198,7 @@
Protected
promise
@@ -206,7 +206,7 @@
Protected
worker
@@ -214,7 +214,7 @@
Readonly
workerAccessors
Returns boolean
Protected
Abstract
full
@@ -238,7 +238,7 @@
Returns boolean
Private
number
@@ -248,7 +248,7 @@
Returns number
Private
number
@@ -258,7 +258,7 @@
Returns number
Abstract
type
@@ -270,7 +270,7 @@
Returns PoolType
Methods
Protected
Abstract
afterProtected
beforePrivate
buildPrivate
checkPrivate
checkPrivate
checkPrivate
checkPrivate
checkPrivate
checkProtected
chooseChooses a worker node for the next task.
The default uses a round robin algorithm to distribute the load.
- -[worker node key, worker node].
Protected
createCreates a new worker and sets it up completely in the pool worker nodes.
- -New, completely set up worker.
New, completely set up worker.
+Protected
Abstract
createPrivate
dequeueImplementation of IPool.destroy
Protected
Abstract
destroyImplementation of IPool.enableTasksQueue
Private
enqueueExecutes the function specified in the worker constructor with the task data input parameter.
- -Promise that will be fulfilled when the task is completed.
Optional
data: DataThe task input data for the specified worker function. This can only be serializable data.
Promise that will be fulfilled when the task is completed.
+Implementation of IPool.execute
Private
executePrivate
flushPrivate
flushPrivate
flushPrivate
getGets the given worker its worker node key.
- -The worker node key if the worker is found in the pool worker nodes, -1
otherwise.
The worker.
The worker node key if the worker is found in the pool worker nodes, -1
otherwise.
Private
getGets the given worker its tasks usage in the pool.
Error if the worker is not found in the pool worker nodes.
- -The worker tasks usage.
The worker.
The worker tasks usage.
+Protected
internalProtected
Abstract
isPrivate
pushPushes the given worker in the pool worker nodes.
- -The worker nodes length.
The worker.
The worker nodes length.
+Protected
Abstract
registerRegisters a listener callback on the given worker.
Private
removeProtected
Abstract
sendImplementation of IPool.setTasksQueueOptions
Implementation of IPool.setWorkerChoiceStrategy
Implementation of IPool.setWorkerChoiceStrategyOptions
Private
setPrivate
setProtected
setupPrivate
tasksProtected
workerThis function is the listener registered for each worker message.
- -The listener function to execute when a message is received from a worker.
The listener function to execute when a message is received from a worker.
+This function is the listener registered for each worker message.
- -The listener function to execute when a message is received from a worker.
The listener function to execute when a message is received from a worker.
+AsyncResource
to which the function is bound.
be thrown if it is called more than once. This must be manually called. If
the resource is left to be collected by the GC then the destroy
hooks will
never be called.
-
-A reference to asyncResource
.
A reference to asyncResource
.
Inherited from AsyncResource.emitDestroy
Protected
getReturns the main worker.
- -Reference to the main worker.
Reference to the main worker.
+Protected
handleHandles an error and convert it to a string so it can be sent back to the main worker.
- -Message of the error.
The error raised by the worker.
Message of the error.
+Protected
messageProtected
runProtected
runv9.6.0
-Inherited from AsyncResource.runInAsyncScope
Protected
Abstract
sendThe same triggerAsyncId
that is passed to the AsyncResource
constructor.
The same triggerAsyncId
that is passed to the AsyncResource
constructor.
Inherited from AsyncResource.triggerAsyncId
Static
bindAsyncResource
to which the function is bound.
v14.8.0, v12.19.0
-AsyncResource
to which the function is bound.
Inherited from AsyncResource.bind
Inherited from FixedThreadPool.opts
Protected
promiseInherited from FixedThreadPool.promiseResponseMap
Protected
workerInherited from FixedThreadPool.workerChoiceStrategyContext
Readonly
workerInherited from FixedThreadPool.workerNodes
Overrides FixedThreadPool.busy
Protected
fullOverrides FixedThreadPool.full
Private
numberInherited from FixedThreadPool.numberOfQueuedTasks
Private
numberInherited from FixedThreadPool.numberOfRunningTasks
Overrides FixedThreadPool.type
Inherited from FixedThreadPool.afterTaskExecutionHook
Protected
afterInherited from FixedThreadPool.afterWorkerSetup
Protected
beforeInherited from FixedThreadPool.beforeTaskExecutionHook
Protected
chooseChooses a worker node for the next task.
The default uses a round robin algorithm to distribute the load.
- -[worker node key, worker node].
[worker node key, worker node].
+Inherited from FixedThreadPool.chooseWorkerNode
Protected
createCreates a new worker and sets it up completely in the pool worker nodes.
- -New, completely set up worker.
New, completely set up worker.
+Inherited from FixedThreadPool.createAndSetupWorker
Protected
createInherited from FixedThreadPool.createWorker
Inherited from FixedThreadPool.destroy
Protected
destroyInherited from FixedThreadPool.destroyWorker
Inherited from FixedThreadPool.enableTasksQueue
Executes the function specified in the worker constructor with the task data input parameter.
- -Promise that will be fulfilled when the task is completed.
Optional
data: DataThe task input data for the specified worker function. This can only be serializable data.
Promise that will be fulfilled when the task is completed.
+Inherited from FixedThreadPool.execute
Protected
internalInherited from FixedThreadPool.internalBusy
Protected
isInherited from FixedThreadPool.isMain
Protected
registerRegisters a listener callback on the given worker.
Inherited from FixedThreadPool.registerWorkerMessageListener
Protected
sendInherited from FixedThreadPool.sendToWorker
Inherited from FixedThreadPool.setTasksQueueOptions
Inherited from FixedThreadPool.setWorkerChoiceStrategy
Inherited from FixedThreadPool.setWorkerChoiceStrategyOptions
Protected
setupInherited from FixedThreadPool.setupHook
Protected
workerThis function is the listener registered for each worker message.
- -The listener function to execute when a message is received from a worker.
The listener function to execute when a message is received from a worker.
+This function is the listener registered for each worker message.
- -The listener function to execute when a message is received from a worker.
The listener function to execute when a message is received from a worker.
+Inherited from FixedThreadPool.workerListener
Inherited from AbstractPool.numberOfWorkers
Readonly
optsInherited from AbstractPool.opts
Protected
promiseInherited from AbstractPool.promiseResponseMap
Protected
workerInherited from AbstractPool.workerChoiceStrategyContext
Readonly
workerInherited from AbstractPool.workerNodes
Overrides AbstractPool.busy
Protected
fullOverrides AbstractPool.full
Private
numberInherited from AbstractPool.numberOfQueuedTasks
Private
numberInherited from AbstractPool.numberOfRunningTasks
Overrides AbstractPool.type
Inherited from AbstractPool.afterTaskExecutionHook
Protected
afterOverrides AbstractPool.afterWorkerSetup
Protected
beforeInherited from AbstractPool.beforeTaskExecutionHook
Protected
chooseChooses a worker node for the next task.
The default uses a round robin algorithm to distribute the load.
- -[worker node key, worker node].
[worker node key, worker node].
+Inherited from AbstractPool.chooseWorkerNode
Protected
createCreates a new worker and sets it up completely in the pool worker nodes.
- -New, completely set up worker.
New, completely set up worker.
+Inherited from AbstractPool.createAndSetupWorker
Protected
createOverrides AbstractPool.createWorker
Inherited from AbstractPool.destroy
Protected
destroyOverrides AbstractPool.destroyWorker
Inherited from AbstractPool.enableTasksQueue
Executes the function specified in the worker constructor with the task data input parameter.
- -Promise that will be fulfilled when the task is completed.
Optional
data: DataThe task input data for the specified worker function. This can only be serializable data.
Promise that will be fulfilled when the task is completed.
+Inherited from AbstractPool.execute
Protected
internalInherited from AbstractPool.internalBusy
Protected
isOverrides AbstractPool.isMain
Protected
registerRegisters a listener callback on the given worker.
Overrides AbstractPool.registerWorkerMessageListener
Protected
sendOverrides AbstractPool.sendToWorker
Inherited from AbstractPool.setTasksQueueOptions
Inherited from AbstractPool.setWorkerChoiceStrategy
Inherited from AbstractPool.setWorkerChoiceStrategyOptions
Protected
setupOverrides AbstractPool.setupHook
Protected
workerThis function is the listener registered for each worker message.
- -The listener function to execute when a message is received from a worker.
The listener function to execute when a message is received from a worker.
+This function is the listener registered for each worker message.
- -The listener function to execute when a message is received from a worker.
The listener function to execute when a message is received from a worker.
+Inherited from AbstractPool.workerListener
Inherited from AbstractPool.numberOfWorkers
Readonly
optsInherited from AbstractPool.opts
Protected
promiseInherited from AbstractPool.promiseResponseMap
Protected
workerInherited from AbstractPool.workerChoiceStrategyContext
Readonly
workerInherited from AbstractPool.workerNodes
Overrides AbstractPool.busy
Protected
fullOverrides AbstractPool.full
Private
numberInherited from AbstractPool.numberOfQueuedTasks
Private
numberInherited from AbstractPool.numberOfRunningTasks
Overrides AbstractPool.type
Inherited from AbstractPool.afterTaskExecutionHook
Protected
afterOverrides AbstractPool.afterWorkerSetup
Protected
beforeInherited from AbstractPool.beforeTaskExecutionHook
Protected
chooseChooses a worker node for the next task.
The default uses a round robin algorithm to distribute the load.
- -[worker node key, worker node].
[worker node key, worker node].
+Inherited from AbstractPool.chooseWorkerNode
Protected
createCreates a new worker and sets it up completely in the pool worker nodes.
- -New, completely set up worker.
New, completely set up worker.
+Inherited from AbstractPool.createAndSetupWorker
Protected
createOverrides AbstractPool.createWorker
Inherited from AbstractPool.destroy
Protected
destroyOverrides AbstractPool.destroyWorker
Inherited from AbstractPool.enableTasksQueue
Executes the function specified in the worker constructor with the task data input parameter.
- -Promise that will be fulfilled when the task is completed.
Optional
data: DataThe task input data for the specified worker function. This can only be serializable data.
Promise that will be fulfilled when the task is completed.
+Inherited from AbstractPool.execute
Protected
internalInherited from AbstractPool.internalBusy
Protected
isOverrides AbstractPool.isMain
Protected
registerRegisters a listener callback on the given worker.
Overrides AbstractPool.registerWorkerMessageListener
Protected
sendOverrides AbstractPool.sendToWorker
Inherited from AbstractPool.setTasksQueueOptions
Inherited from AbstractPool.setWorkerChoiceStrategy
Inherited from AbstractPool.setWorkerChoiceStrategyOptions
Protected
setupInherited from AbstractPool.setupHook
Protected
workerThis function is the listener registered for each worker message.
- -The listener function to execute when a message is received from a worker.
The listener function to execute when a message is received from a worker.
+This function is the listener registered for each worker message.
- -The listener function to execute when a message is received from a worker.
The listener function to execute when a message is received from a worker.
+Inherited from AbstractPool.workerListener
Inherited from EventEmitter.emit
Returns an array listing the events for which the emitter has registered
listeners. The values in the array are strings or Symbol
s.
const EventEmitter = require('events');
const myEE = new EventEmitter();
myEE.on('foo', () => {});
myEE.on('bar', () => {});
const sym = Symbol('symbol');
myEE.on(sym, () => {});
console.log(myEE.eventNames());
// Prints: [ 'foo', 'bar', Symbol(symbol) ]
-
+
v6.0.0
Inherited from EventEmitter.eventNames
emitter.setMaxListeners(n)
or defaults to Returns numberInherited from EventEmitter.getMaxListeners
emitter.setMaxListeners(n)
or defaults to Returns numberInherited from EventEmitter.listenerCount
emitter.setMaxListeners(n)
or defaults to
Returns a copy of the array of listeners for the event named eventName
.
server.on('connection', (stream) => {
console.log('someone connected!');
});
console.log(util.inspect(server.listeners('connection')));
// Prints: [ [Function] ]
-
+
v0.1.26
emitter.setMaxListeners(n)
or defaults to Returns Function[]Inherited from EventEmitter.listeners
emitter.setMaxListeners(n)
or defaults to Returns PoolEmitterInherited from EventEmitter.off
eventName
. No checks are made to see if the liste
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.on('connection', (stream) => {
console.log('someone connected!');
});
-
+
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.on('foo', () => console.log('a'));
myEE.prependListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
-
+
v0.1.101
@@ -318,7 +318,7 @@ event listener to the beginning of the listeners array.Inherited from EventEmitter.on
Adds a one-timelistener
function for the event named eventName
. The
next time eventName
is triggered, this listener is removed and then invoked.
server.once('connection', (stream) => {
console.log('Ah, we have our first user!');
});
-
+
Returns a reference to the EventEmitter
, so that calls can be chained.
By default, event listeners are invoked in the order they are added. Theemitter.prependOnceListener()
method can be used as an alternative to add the
event listener to the beginning of the listeners array.
const myEE = new EventEmitter();
myEE.once('foo', () => console.log('a'));
myEE.prependOnceListener('foo', () => console.log('b'));
myEE.emit('foo');
// Prints:
// b
// a
-
+
v0.3.0
Inherited from EventEmitter.once
eventName
. No checks are made to see if the liste
already been added. Multiple calls passing the same combination of eventName
and listener
will result in the listener
being added, and called, multiple
times.
server.prependListener('connection', (stream) => {
console.log('someone connected!');
});
-
+
Returns a reference to the EventEmitter
, so that calls can be chained.
v6.0.0
@@ -402,7 +402,7 @@ times.Inherited from EventEmitter.prependListener
Adds a one-timelistener
function for the event named eventName
to the beginning of the listeners array. The next time eventName
is triggered, this
listener is removed, and then invoked.
server.prependOnceListener('connection', (stream) => {
console.log('Ah, we have our first user!');
});
-
+
Returns a reference to the EventEmitter
, so that calls can be chained.
v6.0.0
@@ -441,7 +441,7 @@ listener is removed, and then invoked.Inherited from EventEmitter.prependOnceListener
Returns a copy of the array of listeners for the event named eventName
,
including any wrappers (such as those created by .once()
).
const emitter = new EventEmitter();
emitter.once('log', () => console.log('log once'));
// Returns a new Array with a function `onceWrapper` which has a property
// `listener` which contains the original listener bound above
const listeners = emitter.rawListeners('log');
const logFnWrapper = listeners[0];
// Logs "log once" to the console and does not unbind the `once` event
logFnWrapper.listener();
// Logs "log once" to the console and removes the listener
logFnWrapper();
emitter.on('log', () => console.log('log persistently'));
// Will return a new Array with a single function bound by `.on()` above
const newListeners = emitter.rawListeners('log');
// Logs "log persistently" twice
newListeners[0]();
emitter.emit('log');
-
+
v9.4.0
.once()
).
Inherited from EventEmitter.rawListeners
Inherited from EventEmitter.removeAllListeners
Removes the specified listener
from the listener array for the event namedeventName
.
const callback = (stream) => {
console.log('someone connected!');
};
server.on('connection', callback);
// ...
server.removeListener('connection', callback);
-
+
removeListener()
will remove, at most, one instance of a listener from the
listener array. If any single listener has been added multiple times to the
listener array for the specified eventName
, then removeListener()
must be
@@ -501,7 +501,7 @@ called multiple times to remove each instance.
removeListener()
or removeAllListeners()
calls after emitting and before the last listener finishes execution
will not remove them fromemit()
in progress. Subsequent events behave as expected.
const myEmitter = new MyEmitter();
const callbackA = () => {
console.log('A');
myEmitter.removeListener('event', callbackB);
};
const callbackB = () => {
console.log('B');
};
myEmitter.on('event', callbackA);
myEmitter.on('event', callbackB);
// callbackA removes listener callbackB but it will still be called.
// Internal listener array at time of emit [callbackA, callbackB]
myEmitter.emit('event');
// Prints:
// A
// B
// callbackB is now removed.
// Internal listener array [callbackA]
myEmitter.emit('event');
// Prints:
// A
-
+
Because listeners are managed using an internal array, calling this will
change the position indices of any listener registered after the listener
being removed. This will not impact the order in which listeners are called,
@@ -511,7 +511,7 @@ the emitter.listeners()
method will need to be recreated.
removeListener()
will remove the most
recently added instance. In the example the once('ping')
listener is removed:
const ee = new EventEmitter();
function pong() {
console.log('pong');
}
ee.on('ping', pong);
ee.once('ping', pong);
ee.removeListener('ping', pong);
ee.emit('ping');
ee.emit('ping');
-
+
Returns a reference to the EventEmitter
, so that calls can be chained.
v0.1.26
@@ -537,7 +537,7 @@ recently added instance. In the example theonce('ping')
lis
Inherited from EventEmitter.removeListener
EventEmitter
instance. The value can be
Inherited from EventEmitter.setMaxListeners
Static
getFor EventTarget
s this is the only way to get the event listeners for the
event target. This is useful for debugging and diagnostic purposes.
const { getEventListeners, EventEmitter } = require('events');
{
const ee = new EventEmitter();
const listener = () => console.log('Events are fun');
ee.on('foo', listener);
getEventListeners(ee, 'foo'); // [listener]
}
{
const et = new EventTarget();
const listener = () => console.log('Events are fun');
et.addEventListener('foo', listener);
getEventListeners(et, 'foo'); // [listener]
}
-
+
v15.2.0, v14.17.0
Inherited from EventEmitter.getEventListeners
Static
listenerA class method that returns the number of listeners for the given eventName
registered on the given emitter
.
const { EventEmitter, listenerCount } = require('events');
const myEmitter = new EventEmitter();
myEmitter.on('event', () => {});
myEmitter.on('event', () => {});
console.log(listenerCount(myEmitter, 'event'));
// Prints: 2
-
+
v0.9.12
@@ -613,25 +613,23 @@ event target. This is useful for debugging and diagnostic purposes.Inherited from EventEmitter.listenerCount
Static
onconst { on, EventEmitter } = require('events');
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo')) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
-
+
Returns an AsyncIterator
that iterates eventName
events. It will throw
if the EventEmitter
emits 'error'
. It removes all listeners when
exiting the loop. The value
returned by each iteration is an array
composed of the emitted event arguments.
An AbortSignal
can be used to cancel waiting on events:
const { on, EventEmitter } = require('events');
const ac = new AbortController();
(async () => {
const ee = new EventEmitter();
// Emit later on
process.nextTick(() => {
ee.emit('foo', 'bar');
ee.emit('foo', 42);
});
for await (const event of on(ee, 'foo', { signal: ac.signal })) {
// The execution of this inner block is synchronous and it
// processes one event at a time (even with await). Do not use
// if concurrent execution is required.
console.log(event); // prints ['bar'] [42]
}
// Unreachable here
})();
process.nextTick(() => ac.abort());
-
+
v13.6.0, v12.16.0
- -that iterates eventName
events emitted by the emitter
Optional
options: StaticEventEmitterOptionsthat iterates eventName
events emitted by the emitter
Inherited from EventEmitter.on
Static
onceThis method is intentionally generic and works with the web platform EventTarget interface, which has no special'error'
event
semantics and does not listen to the 'error'
event.
const { once, EventEmitter } = require('events');
async function run() {
const ee = new EventEmitter();
process.nextTick(() => {
ee.emit('myevent', 42);
});
const [value] = await once(ee, 'myevent');
console.log(value);
const err = new Error('kaboom');
process.nextTick(() => {
ee.emit('error', err);
});
try {
await once(ee, 'myevent');
} catch (err) {
console.log('error happened', err);
}
}
run();
-
+
The special handling of the 'error'
event is only used when events.once()
is used to wait for another event. If events.once()
is used to wait for the
'error'
event itself, then it is treated as any other kind of event without
special handling:
const { EventEmitter, once } = require('events');
const ee = new EventEmitter();
once(ee, 'error')
.then(([err]) => console.log('ok', err.message))
.catch((err) => console.log('error', err.message));
ee.emit('error', new Error('boom'));
// Prints: ok boom
-
+
An AbortSignal
can be used to cancel waiting for the event:
const { EventEmitter, once } = require('events');
const ee = new EventEmitter();
const ac = new AbortController();
async function foo(emitter, event, signal) {
try {
await once(emitter, event, { signal });
console.log('event emitted!');
} catch (error) {
if (error.name === 'AbortError') {
console.error('Waiting for the event was canceled!');
} else {
console.error('There was an error', error.message);
}
}
}
foo(ee, 'foo', ac.signal);
ac.abort(); // Abort waiting for the event
ee.emit('foo'); // Prints: Waiting for the event was canceled!
-
+
v11.13.0, v10.16.0
Inherited from EventEmitter.once
Inherited from EventEmitter.once
Static
setconst {
setMaxListeners,
EventEmitter
} = require('events');
const target = new EventTarget();
const emitter = new EventEmitter();
setMaxListeners(5, target, emitter);
-
+
v15.4.0
Inherited from EventEmitter.setMaxListeners
Inherited from AbstractWorker.lastTaskTimestamp
Protected
mainInherited from AbstractWorker.mainWorker
Protected
Readonly
optsInherited from AbstractWorker.opts
The unique asyncId
assigned to the resource.
The unique asyncId
assigned to the resource.
Inherited from AbstractWorker.asyncId
AsyncResource
to which the function is bound.
v14.8.0, v12.19.0
-AsyncResource
to which the function is bound.
Inherited from AbstractWorker.bind
Protected
checkAsyncResource
to which the function is bound.
Inherited from AbstractWorker.checkAlive
AsyncResource
to which the function is bound.
be thrown if it is called more than once. This must be manually called. If
the resource is left to be collected by the GC then the destroy
hooks will
never be called.
-
-A reference to asyncResource
.
A reference to asyncResource
.
Inherited from AbstractWorker.emitDestroy
Protected
getReturns the main worker.
- -Reference to the main worker.
Reference to the main worker.
+Inherited from AbstractWorker.getMainWorker
Protected
handleHandles an error and convert it to a string so it can be sent back to the main worker.
- -Message of the error.
The error raised by the worker.
Message of the error.
+Inherited from AbstractWorker.handleError
Protected
messageInherited from AbstractWorker.messageListener
Protected
runInherited from AbstractWorker.run
Protected
runInherited from AbstractWorker.runAsync
v9.6.0
-Inherited from AbstractWorker.runInAsyncScope
Protected
sendOverrides AbstractWorker.sendToMainWorker
The same triggerAsyncId
that is passed to the AsyncResource
constructor.
The same triggerAsyncId
that is passed to the AsyncResource
constructor.
Inherited from AbstractWorker.triggerAsyncId
Static
bindAsyncResource
to which the function is bound.
v14.8.0, v12.19.0
-AsyncResource
to which the function is bound.
Inherited from AbstractWorker.bind
Inherited from PoolOptions.errorHandler
Optional
exitInherited from PoolOptions.exitHandler
Optional
messageInherited from PoolOptions.messageHandler
Optional
onlineInherited from PoolOptions.onlineHandler
Optional
settingshttps://nodejs.org/api/cluster.html#cluster_cluster_settings
Optional
tasksInherited from PoolOptions.tasksQueueOptions
Optional
workerInherited from PoolOptions.workerChoiceStrategy
Optional
workerInherited from PoolOptions.workerChoiceStrategyOptions
Executes the function specified in the worker constructor with the task data input parameter.
- -Promise that will be fulfilled when the task is completed.
Optional
data: DataThe task input data for the specified worker function. This can only be serializable data.
Promise that will be fulfilled when the task is completed.
+Readonly
typeIf it is 'dynamic'
, it provides the max
property.
Readonly
workerPool worker nodes.
Readonly
requiredRequired tasks usage statistics.
Readonly
workerThe worker handling the execution.
Base class that implements some shared logic for all poolifier pools.