Get support for soyuka/IPCEE
If you're new to LTH, please see our FAQ for more information on what it is we do.
Support Options
Unfortunately, there are currently no active helpers for this repository on the platform. Until they become available, we reccomend the following actions:
View Open IssuesTake a look to see if anyone else has experienced the same issue as you and if they managed to solve it.
Open an IssueMake sure to read any relevant guidelines for opening issues on this repo before posting a new issue.
Sponsor directlyCheck out the page and see if there are any options to sponsor this project or it's developers directly.
soyuka/IPCEE
IPC EE 
IPC combined with EventEmitter2
What for?
First, RTFM child.send(message[, sendHandle]).
The sendHandle option to child.send() is for sending a TCP server or socket object to another process. The child will receive the object as its second argument to the message event.
This means that you won't be able to do things like:
child.send('message', {some: 'data'}, [data])
This library still works with the list of accepted instances. Also, if you look a but further in the code, internal messages are handled first. As stated in the docs:
There is a special case when sending a {cmd: 'NODE_foo'} message.
Things apart, this is a fancier api to communicate with child processes!
Note that I consider this as a low-level module, if you want a higher communication api, take a look at relieve. I also made a module with the same api using TCP instead of IPC: TCPEE.
Usage
Test for child start:
Child
ipc.send('started')
Master
const child = fork('child')
child.once('started', dosomething)
Play ping pong:
Child
const ipc = IPCEE(process)
ipc.send('started')
ipc.on('ping', function() {
ipc.send('pong')
})
Master
const server = fork('some/node/app.js')
const client = IPCEE(server)
client.once('started', () => {
client.send('ping')
})
client.once('pong', () => {
console.log('\o/')
})
Or play with namespaces:
Child
const ipc = IPCEE(process, {wildcard: true, delimiter: ':'})
ipc.send('started')
ipc.on('ping:me', () => {
ipc.send('me:pong')
})
Master
const server = fork('some/node/app.js')
const client = IPCEE(server, {wildcard: true, delimiter: ':'})
client.once('started', () => {
client.send('ping:*')
})
client.once('*:pong', () => {
console.log('\o/')
})
Caveat
Using the first argument of child_process.send(), Nodejs IPC will transport strings. Javascript objects are encoded with json internally. That said, You won't be able to pass instances.
Example:
process.on('uncaughtException', err => {
ipc.send('error', err.toString(), err.stack)
process.nextTick(() => {
process.exit(1)
})
})
Here, Temptation would be to send the full Error object but JSON.stringify(new Error('test')
) will return '{}'
.
Note, I made a js to string proof of concept here, it could work in some cases.
Native IPC features
IPCEE does not override any of the internals methods. This means that you'll still be able to get messages from the standard way:
process.on('message', (m, handle) => {
if(m === 'server') {
//do something with handle
}
})
But it will handle accepted instances in an easy way too. For example, sending a Socket:
//server.js
ipc.send('socket', sock)
//child.js
ipc.on('socket', (sock) => {
assert(sock instanceof Socket)
})
API
/**
* Constructor
* @param socket - the process/child_process to write/read to/from
* @param options - eventemitter2 options
*/
const ipcee = new IPCEE(process, {wildcard: true})
/**
* @param key - the key you'll listen on
* @param ...args
*/
ipcee.send('key', arg1, arg2)
/**
* @param key
* @param ...args data received
*/
ipcee.on('key', function(arg1, arg2) {
})
Apart from the send
method, the api inherits the one of EventEmitter2.
Licence
The MIT License (MIT)
Copyright (c) 2015 Antoine Bluchet
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Our Mission
We want to make open source more sustainable. The entire platform was born from this and everything we do is in aid of this.
From the Blog
Interesting Articles
-
Generating income from open source
Jun 23 • 8 min read
-
2023 State of OSS
Apr 23 • 45 min read ★
-
A funding experiment...
Aug 19 • 10 min read
-
But You Said I could
Aug 19 • 2 min read
Thank you for checking out LiveTechHelper |
2025 © lth-dev incorporated
p-e622a1a2