Skip to content

Commit

Permalink
[email protected]: removed closeIPC from callback
Browse files Browse the repository at this point in the history
  • Loading branch information
nathanschwarz committed Jan 21, 2021
1 parent 98d2ab0 commit 1a6044e
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 30 deletions.
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ All communications between the master and a child must be started by the child.
To do so you can use the second parameter passed in all functions provided to the taskMap `toggleIPC` which is prototyped as follow :

`toggleIPC(messageBroker: function, initalize: function): Promise`
- `messageBroker` is prototyped as `messageBroker(msg: Any, closeIPC: function)`
- `messageBroker` is prototyped as `messageBroker(msg: Any)`
- `initialize` is prototyped as `initialize(sendMessageToMaster: function)`<br/>

because `toggleIPC` returns a promise you must return it (recursively), otherwise the job will be considered done, and the worker Idle.<br/>
Expand Down Expand Up @@ -210,11 +210,10 @@ in such case your overall system should be **slowed down** because some of the p
```
function ipcPingTest(job, toggleIPC) {
return toggleIPC(
(msg, closeIPC) => {
(msg) => {
console.log(msg)
const result = 'result you eventually want to pass to the master'
closeIPC(result)
}, (sendMessageToMaster) => sendMessageToMaster({ status: 4, data: 'ping' })
return 'result you eventually want to pass to the master'
}, (smtm) => smtm({ status: 4, data: 'ping' })
)
}
Expand All @@ -235,17 +234,13 @@ const cluster = new Cluster(taskMap, { messageBroker })
```
function ipcPingTest(job, toggleIPC) {
return toggleIPC(
(msg, closeIPC) => {
(msg) => {
console.log(msg)
closeIPC(
toggleIPC(
(msg, closeIPC) => {
console.log(msg)
closeIPC()
}, (sendMessageToMaster) => sendMessageToMaster({ status: 4, data: 'ping' })
return toggleIPC(
(msg) => console.log(msg),
(smtm) => smtm({ status: 4, data: 'ping' })
)
)
}, (sendMessageToMaster) => sendMessageToMaster({ status: 4, data: 'ping' }))
}, (smtm) => smtm({ status: 4, data: 'ping' }))
}
const taskMap = {
Expand Down
2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package.describe({
name: 'nschwarz:cluster',
version: '2.0.1',
version: '2.1.0',
summary: 'native nodejs clusterization for meteor server',
git: 'https://github.com/nathanschwarz/meteor-cluster.git',
documentation: 'README.md'
Expand Down
4 changes: 2 additions & 2 deletions src/Worker/ChildWorker.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ChildWorker {
static toggleIPC(messageBroker, initialize) {
return new Promise((resolve, reject) => {
process.removeAllListeners('message')
process.on('message', (msg) => messageBroker(msg, resolve))
process.on('message', (msg) => resolve(messageBroker(msg)))
initialize(ChildWorker.sendMsg)
}).catch(e => {
throw new Error(e)
Expand Down Expand Up @@ -50,4 +50,4 @@ class ChildWorker {
}
}

export default ChildWorker
export default ChildWorker
19 changes: 6 additions & 13 deletions src/tests/ipcTests.js
Original file line number Diff line number Diff line change
@@ -1,23 +1,16 @@
function ipcSinglePingTest(job, toggleIPC) {
return toggleIPC(
(msg, closeIPC) => {
console.log(`\n\n${msg}\n\n`)
closeIPC()
}, (smtm) => smtm({ status: 4, data: 'ping' })
(msg) => console.log(`\n\n${msg}\n\n`),
(smtm) => smtm({ status: 4, data: 'ping' })
)
}

function ipcMultiPingTest(job, toggleIPC) {
return toggleIPC(
(msg, closeIPC) => {
return toggleIPC((msg) => {
console.log(`\n\n${msg}\n\n`)
closeIPC(
toggleIPC(
(msg, closeIPC) => {
console.log(`\n\n${msg}\n\n`)
closeIPC()
}, (smtm) => smtm({ status: 4, data: 'ping' })
)
return toggleIPC(
(msg) => console.log(`\n\n${msg}\n\n`),
(smtm) => smtm({ status: 4, data: 'ping' })
)
}, (smtm) => smtm({ status: 4, data: 'ping' })
)
Expand Down

0 comments on commit 1a6044e

Please sign in to comment.