A node module for smart subprocess handling with support for promises and streamlined subprocess communication.
|
||
---|---|---|
dist | ||
test | ||
ts | ||
.gitignore | ||
.gitlab-ci.yml | ||
npmextra.json | ||
package.json | ||
README.md | ||
tslint.json |
smartipc
smart subprocess handling
Availabililty
Status for master
The purpose
smartipc makes it easy to spawn tasks into subprocesses without loosing control over what those processes do. You can transparently call functions and expect returned data using promises.
Usage
Server:
import {Ipcserver} from 'smartipc'
import * as q from 'q'
let myIpcserver = new Ipcserver({
appspace: 'mymodule'
})
// The subprocess js file cannot have any cli arguments
// since this mechanism is used by IpcServer to setup the connection
myIpcServer.spawnProcess('./myFile','mySubProcessNameAlias') // nameAlias identifies the subprocess and will prefix any logs from child Process
let someData = {
key1: 'value1',
key2: 'value2'
}
myIpcServer.call('mySubProcessNameAlias','myAwesomeFunction',someData).then(someAnswerData => {
console.log(someAnswerData.key1)
})
Client:
import { Ipcclient } from './smartipc'
import * as q from 'q'
let localIpc = new Ipcclient() // gets its connection information automatically using CLI args internally
let myAwesomeFunction = (dataArg) => {
let done = plugins.q.defer()
console.log('awesome') // this will log transparently in the same console stream as the host process
let someAnswerData = {key1: 'this is an answer'}
done.resolve(someAnswerData)
return done.promise
}
localIpc.register([myAwesomeFunction])