think-cluster
Advanced tools
Comparing version 1.2.0 to 1.3.0
@@ -93,2 +93,3 @@ const cluster = require('cluster'); | ||
broadcast(action, data) { | ||
assert(this.listenerCount(action) > 0, `can not find \`${action}\` listeners`); | ||
process.send({ | ||
@@ -130,5 +131,12 @@ act: MESSENGER, | ||
*/ | ||
consume(callback) { | ||
assert(helper.isFunction(callback), 'callback must be a function'); | ||
const action = `think-messenger-${taskId++}`; | ||
consume(action) { | ||
if (helper.isFunction(action)) { | ||
const callback = action; | ||
action = `think-messenger-${taskId++}`; | ||
this.once(action, callback); | ||
// remove event callback after timeout, avoid memory leak | ||
helper.timeout(10000).then(() => this.removeAllListeners(action)); | ||
} else { | ||
assert(this.listenerCount(action) > 0, `can not find \`${action}\` listeners`); | ||
} | ||
process.send({ | ||
@@ -139,5 +147,2 @@ act: MESSENGER, | ||
}); | ||
this.once(action, callback); | ||
// remove event callback after timeout, avoid memory leak | ||
helper.timeout(10000).then(() => this.removeAllListeners(action)); | ||
} | ||
@@ -144,0 +149,0 @@ } |
{ | ||
"name": "think-cluster", | ||
"description": "Cluster manage for ThinkJS", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"author": { | ||
@@ -6,0 +6,0 @@ "name": "welefen", |
@@ -15,2 +15,5 @@ const test = require('ava'); | ||
} | ||
listenerCount(){ | ||
return 1; | ||
} | ||
emit() {} | ||
@@ -83,3 +86,2 @@ } | ||
const m = new Messenger(); | ||
m.broadcast(() => {}, 'test'); | ||
@@ -86,0 +88,0 @@ }); |
50712
1772