Reviewed InputWorker

This commit is contained in:
n1474335 2023-01-19 16:56:07 +00:00
parent 91f1be8c70
commit 934efcc5a0
2 changed files with 20 additions and 35 deletions

View File

@ -738,8 +738,8 @@ class WorkerWaiter {
* Sets the console log level in the workers. * Sets the console log level in the workers.
*/ */
setLogLevel() { setLogLevel() {
this.chefWorkers.forEach(w => { this.chefWorkers.forEach(cw => {
w.postMessage({ cw.worker.postMessage({
action: "setLogLevel", action: "setLogLevel",
data: log.getLevel() data: log.getLevel()
}); });

View File

@ -21,8 +21,6 @@ loglevelMessagePrefix(log, {
self.maxWorkers = 4; self.maxWorkers = 4;
self.maxTabs = 1; self.maxTabs = 1;
self.pendingFiles = [];
/** /**
* Dictionary of inputs keyed on the inputNum * Dictionary of inputs keyed on the inputNum
* Each entry is an object with the following type: * Each entry is an object with the following type:
@ -41,6 +39,7 @@ self.pendingFiles = [];
*/ */
self.inputs = {}; self.inputs = {};
self.loaderWorkers = []; self.loaderWorkers = [];
self.pendingFiles = [];
self.currentInputNum = 1; self.currentInputNum = 1;
self.numInputs = 0; self.numInputs = 0;
self.pendingInputs = 0; self.pendingInputs = 0;
@ -172,7 +171,7 @@ self.getLoadProgress = function(inputNum) {
* whole recipe * whole recipe
*/ */
self.autoBake = function(inputNum, progress, step=false) { self.autoBake = function(inputNum, progress, step=false) {
const input = self.getInputObj(inputNum); const input = self.inputs[inputNum];
if (input) { if (input) {
self.postMessage({ self.postMessage({
action: "bakeAllInputs", action: "bakeAllInputs",
@ -190,14 +189,12 @@ self.autoBake = function(inputNum, progress, step=false) {
* Sends a list of inputNums to the workerwaiter * Sends a list of inputNums to the workerwaiter
*/ */
self.bakeAllInputs = function() { self.bakeAllInputs = function() {
const inputNums = Object.keys(self.inputs), const inputNums = Object.keys(self.inputs);
nums = [];
const nums = inputNums
.filter(n => self.inputs[n].status === "loaded")
.map(n => parseInt(n, 10));
for (let i = 0; i < inputNums.length; i++) {
if (self.inputs[inputNums[i]].status === "loaded") {
nums.push(parseInt(inputNums[i], 10));
}
}
self.postMessage({ self.postMessage({
action: "bakeAllInputs", action: "bakeAllInputs",
data: { data: {
@ -215,7 +212,7 @@ self.bakeAllInputs = function() {
* @param {number} bakeId * @param {number} bakeId
*/ */
self.bakeInput = function(inputNum, bakeId) { self.bakeInput = function(inputNum, bakeId) {
const inputObj = self.getInputObj(inputNum); const inputObj = self.inputs[inputNum];
if (inputObj === null || if (inputObj === null ||
inputObj === undefined || inputObj === undefined ||
inputObj.status !== "loaded") { inputObj.status !== "loaded") {
@ -240,16 +237,6 @@ self.bakeInput = function(inputNum, bakeId) {
}); });
}; };
/**
* Gets the stored object for a specific inputNum
*
* @param {number} inputNum - The input we want to get the object for
* @returns {object}
*/
self.getInputObj = function(inputNum) {
return self.inputs[inputNum];
};
/** /**
* Gets the stored value or object for a specific inputNum and sends it to the inputWaiter. * Gets the stored value or object for a specific inputNum and sends it to the inputWaiter.
* *
@ -259,12 +246,11 @@ self.getInputObj = function(inputNum) {
* @param {number} inputData.id - The callback ID for the callback to run when returned to the inputWaiter * @param {number} inputData.id - The callback ID for the callback to run when returned to the inputWaiter
*/ */
self.getInput = function(inputData) { self.getInput = function(inputData) {
const inputNum = inputData.inputNum, const input = self.inputs[inputData.inputNum];
data = (inputData.getObj) ? self.getInputObj(inputNum) : self.inputs[inputNum].buffer;
self.postMessage({ self.postMessage({
action: "getInput", action: "getInput",
data: { data: {
data: data, data: inputData.getObj ? input : input.buffer,
id: inputData.id id: inputData.id
} }
}); });
@ -298,8 +284,8 @@ self.getInputNums = function(id) {
* @returns {number | string} - Returns "error" if there was a load error * @returns {number | string} - Returns "error" if there was a load error
*/ */
self.getInputProgress = function(inputNum) { self.getInputProgress = function(inputNum) {
const inputObj = self.getInputObj(inputNum); const inputObj = self.inputs[inputNum];
if (inputObj === undefined || inputObj === null) return; if (!inputObj) return;
if (inputObj.status === "error") { if (inputObj.status === "error") {
return "error"; return "error";
} }
@ -416,11 +402,11 @@ self.getNearbyNums = function(inputNum, direction) {
* @param {number} inputNum - The inputNum of the tab header * @param {number} inputNum - The inputNum of the tab header
*/ */
self.updateTabHeader = function(inputNum) { self.updateTabHeader = function(inputNum) {
const input = self.getInputObj(inputNum); const input = self.inputs[inputNum];
if (input === null || input === undefined) return; if (!input) return;
let header = input.type === "file" ? input.file.name : input.stringSample; let header = input.type === "file" ? input.file.name : input.stringSample;
header = header.slice(0, 100).replace(/[\n\r]/g, ""); header = header.slice(0, 100).replace(/[\n\r\u2028\u2029]/g, "");
self.postMessage({ self.postMessage({
action: "updateTabHeader", action: "updateTabHeader",
@ -441,8 +427,8 @@ self.updateTabHeader = function(inputNum) {
*/ */
self.setInput = function(inputData) { self.setInput = function(inputData) {
const {inputNum, silent} = inputData; const {inputNum, silent} = inputData;
const input = self.getInputObj(inputNum); const input = self.inputs[inputNum];
if (input === undefined || input === null) return; if (!input) return;
self.postMessage({ self.postMessage({
action: "setInput", action: "setInput",
@ -505,8 +491,7 @@ self.updateInputStatus = function(inputNum, status) {
* @param {number} inputData.progress - The load progress of the input * @param {number} inputData.progress - The load progress of the input
*/ */
self.updateInputProgress = function(inputData) { self.updateInputProgress = function(inputData) {
const inputNum = inputData.inputNum; const {inputNum, progress} = inputData;
const progress = inputData.progress;
if (self.inputs[inputNum] !== undefined) { if (self.inputs[inputNum] !== undefined) {
self.inputs[inputNum].progress = progress; self.inputs[inputNum].progress = progress;