new ProcessDispatcher(moduleName, moduleOpts, logger)
Note: before running dispatching workflow do not forget to init listener on the module. For that purpose, please invoke ModuleProcess.listenIPCMessages in the module root. It will engage module to listen to IPC messages and expose module API available via sub-processing.
Parameters:
Name | Type | Description |
---|---|---|
moduleName |
string | Module name (script file name). E.g. __filename |
moduleOpts |
Object | Options object to pass to the module |
logger |
Object |
- Source:
Methods
(static) dispatchToModule(moduleName, moduleOpts, logger, functionName, params) → {ProcessDispatcher~onReadyCallback}
Dispatch function invocation to existing moduleProcess.
Parameters:
Name | Type | Description |
---|---|---|
moduleName |
string | A js filename containing module function (!) (e.g. module.exports = function() { }). I.e. module that is defined by function. |
moduleOpts |
Object | Will be passed to module-function to create a module instance. |
logger |
||
functionName |
string | Function to be invoked (should be defined on the module). |
params |
Object | Parameters mapping. |
- Source:
Returns:
(static) dispatchToModuleProcess(moduleProcess, functionName, params) → {ProcessDispatcher~onReadyCallback}
Dispatch function invocation to existing moduleProcess.
Parameters:
Name | Type | Description |
---|---|---|
moduleProcess |
||
functionName |
string | Function defined on the module. |
params |
Object | Parameters mapping. |
- Source:
Returns:
(static) listenIPCMessages()
Create listener to catch the IPC messages within the process the module is running in.
- Deprecated:
- This is no longer a part of ProcessDispatcher. Migrated to ModuleProcess.listenIPCMessages.
- Source:
(static) makeModuleProcess(moduleName, moduleOpts, logger) → {ProcessDispatcher~onReadyCallback}
Create a module sub-process and configure its listener to accepts messages.
Parameters:
Name | Type | Description |
---|---|---|
moduleName |
||
moduleOpts |
||
logger |
- Source:
Returns:
dispatch(functionName, params) → {ProcessDispatcher~onReadyCallback}
Dispatch arbitrary function call to available ModuleProcess instance.
The ModuleProcess selection algorithm is round robin based. See getNextProcId in this regard.
Parameters:
Name | Type | Description |
---|---|---|
functionName |
Function name to be called. The desired module wrapped by ModuleProcess should expose API via ProcessDispatcher.listenIPCMessages. The functionName should be a part of that API. | |
params |
The parameters to be passed to the functionName |
- Source:
Returns:
getNextProcId() → {Number}
Implementation of FIFO queue for selecting of pre-forked subprocess ids.
See how ProcessDispatcher.dispatch works in this regard.
- Source:
Returns:
- Type
- Number
preFork(num) → {ProcessDispatcher~onReadyCallback}
Pre-fork subprocess and update a list of available sub-process ids.
Parameters:
Name | Type | Description |
---|---|---|
num |
- Source:
Returns:
updateRRId()
Creates round robin ids for preforked subprocesses. See how ProcessDispatcher.dispatch works.
- Source:
Type Definitions
onReadyCallback(error)
Callback to run on function finished. Note: It might contain arbitrary number of arguments (required at least one - error)
Parameters:
Name | Type | Description |
---|---|---|
error |
Error | An Error object if the callback has raised an error. |
- Source: