abstract the logic around worker choice out of message handling

pull/1/head
ansuz 5 years ago
parent 631ea54b49
commit 9e85a1411e

@ -926,6 +926,7 @@ HK.onDirectMessage = function (Env, Server, seq, userId, json) {
const onChecked = Util.mkEvent();
// Create our workers
const workers = [];
for (let i = 0; i < numCPUs; i++) {
@ -951,6 +952,12 @@ var initWorker = function (worker) {
};
workers.forEach(initWorker);
const validateMessage = function (msg) {
nextWorker = (nextWorker + 1) % workers.length;
// Send the request
workers[nextWorker].send(msg);
};
HK.onChannelMessage = function (Env, Server, channel, msgStruct) {
console.log(+new Date(), "onChannelMessage");
const Log = Env.Log;
@ -1018,13 +1025,11 @@ HK.onChannelMessage = function (Env, Server, channel, msgStruct) {
onChecked.reg(onCheck);
console.log(+new Date(), "Send verification request");
// Send the request
workers[nextWorker].send({
validateMessage( {
txid: txid,
msg: signedMsg,
key: metadata.validateKey
});
if (++nextWorker > numCPUs) { nextWorker = 0; }
}).nThen(function () {
// do checkpoint stuff...

Loading…
Cancel
Save