This commit is contained in:
Holly Stubbs 2021-08-15 11:32:38 +01:00
parent f2b180fedb
commit 59a9ec907f

View file

@ -20,20 +20,22 @@ module.exports = class {
this.toRemove = []; this.toRemove = [];
// WoAh!!! Thread pool in js!?!??!???!11!?!?!
for (let i = 0; i < config.threadPoolCount; i++) { for (let i = 0; i < config.threadPoolCount; i++) {
const worker = new Worker(workerPath); const worker = new Worker(workerPath);
this.threadPool.push([false, worker]); this.threadPool.push([false, worker]);
const myID = i; const myID = i;
worker.on("message", (data) => { worker.on("message", (data) => {
/*const user = global.getUserByKey(message[0]);
for (let square of message[1]) { user.chunksToSend.add(Buffer.from(square)); }
this.threadPool[myID][0] = false;
this.toRemove.push(message[2]);*/
switch (data[0]) { switch (data[0]) {
case "chunk": case "chunk":
const user = global.getUserByKey(data[2]); const user = global.getUserByKey(data[2]);
user.chunksToSend.add(Buffer.from(data[1])); user.chunksToSend.add(Buffer.from(data[1]));
//this.threadPool[myID][0] = false; break;
// Specific to the chunk task as multiple of them are sent before removal
case "remove":
this.toRemove.push(data[1]);
this.threadPool[myID][0] = false;
break; break;
case "generate": case "generate":
@ -41,11 +43,6 @@ module.exports = class {
this.toRemove.push(data[4]); this.toRemove.push(data[4]);
this.threadPool[myID][0] = false; this.threadPool[myID][0] = false;
break; break;
case "remove":
this.toRemove.push(data[1]);
this.threadPool[myID][0] = false;
break;
} }
}); });
} }