@ideadesignmedia/subprocess

1.1.1 • Public • Published

Subprocess Helper

Easily create and manage subprocesses through json signals.

Usage

const { createSubprocess, handleMain } = require('@ideadesignmedia/subprocess')

createSubprocess

createSubprocess(command, args = [], options = {}, onSignal: ({type: string, data: any}) => void) => { child, eventManager request, send, close, id }

Creates a subprocess and returns a function to send signals to it.

Inputs

command - The command to run in the subprocess.

args - The arguments to pass to the command.

options - The options to pass to the child process. If you require ipc for communication use {ipc: true}.

onSignal({type: string, data: any}) => void - A function to handle signals from the subprocess.

Parameters

Object with keys:

type: string - The type of signal received.

data: any - The data received.

Returns

child: ChildProcess - The child process.

eventManager: EventEmitter - The event manager for the child process.

request: (type: string, data: any) => Promise<{type: 'success'|'failure', data: any}> - A function to send a request to the subprocess and wait for a response.

send: ({type: string, data: any}) => void - A function to send a signal to the subprocess.

close: () => void - A function to close the subprocess.

id: string - The id of the subprocess.

handleMain

handleMain(onMessage: ({type: string, data: any}) => void) => { eventManager, sendToMain }

Creates a handler for signals to the subprocess and returns a function to send signals to the main process.

Inputs

onMessage({type: string, data: any}) => void - A function to handle signals from the subprocess.

Parameters

type: string - The type of signal received.

data: any - The data received.

Returns

eventManager: EventEmitter - The event manager for the main process.

sendToMain: ({type: string, data: any}) => void - A function to send a signal to the main process.

Readme

Keywords

none

Package Sidebar

Install

npm i @ideadesignmedia/subprocess

Weekly Downloads

0

Version

1.1.1

License

MIT

Unpacked Size

5.55 kB

Total Files

3

Last publish

Collaborators

  • ideadesignmedia