From 9e85a1411e8507b99e8dc7593bfc8acba39ced62 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 17 Mar 2020 16:06:01 -0400 Subject: [PATCH] abstract the logic around worker choice out of message handling --- lib/hk-util.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/hk-util.js b/lib/hk-util.js index a9b9f0eb1..b3f917693 100644 --- a/lib/hk-util.js +++ b/lib/hk-util.js @@ -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...