Skip to content

Commit

Permalink
Ensure _init_ completes before handling further messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Mattk70 committed Oct 11, 2024
1 parent 4c4f8d5 commit bf6d650
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
2 changes: 1 addition & 1 deletion js/tracking.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const DEBUG = false;
const ID_SITE = 3;
const ID_SITE = 2;


function trackEvent(uuid, event, action, name, value){
Expand Down
1 change: 0 additions & 1 deletion js/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -2695,7 +2695,6 @@ function onChartData(args) {
}
}
PREDICTING = false;
STATE.analysisDone = true;
}
// Update threads and batch Size in UI
DOM.threadSlider.value = config[config[config.model].backend].threads;
Expand Down
16 changes: 12 additions & 4 deletions js/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,26 @@ const dirInfo = async ({ folder = undefined, recursive = false }) => {
return [size, ctimes];
}

let INITIALISED = null;

async function handleMessage(e) {
const args = e.data;
const action = args.action;
DEBUG && console.log('message received', action)
if (action !== "_init_" && INITIALISED) {
// Wait until _init_ or onLaunch completes before processing other messages
await INITIALISED;
}
switch (action) {
case "_init_": {
let {model, batchSize, threads, backend, list} = args;
const t0 = Date.now();
STATE.detect.backend = backend;
LIST_WORKER = await spawnListWorker(); // this can change the backend if tfjs-node isn't available
DEBUG && console.log('List worker took', Date.now() - t0, 'ms to load');
await onLaunch({model: model, batchSize: batchSize, threads: threads, backend: STATE.detect.backend, list: list});
INITIALISED = (async () => {
LIST_WORKER = await spawnListWorker(); // this can change the backend if tfjs-node isn't available
DEBUG && console.log('List worker took', Date.now() - t0, 'ms to load');
await onLaunch({model: model, batchSize: batchSize, threads: threads, backend: STATE.detect.backend, list: list});
})();
break;
}
case "abort": {
Expand Down Expand Up @@ -461,7 +469,7 @@ async function handleMessage(e) {
else {
predictWorkers.length && terminateWorkers()
};
await onLaunch(args);
INITIALISED = onLaunch(args);
break;
}
case "post": {await uploadOpus(args);
Expand Down

0 comments on commit bf6d650

Please sign in to comment.