LoRaWAN-Signal-Mapping/client_src/js/Worker/AI.worker.mjs

37 lines
733 B
JavaScript
Raw Normal View History

"use strict";
import AIWrapper from './AIWrapper.mjs';
let ai_wrapper = new AIWrapper();
async function handle_message(event) {
console.log(event.data);
switch(event.data.event) {
case "setup":
await ai_wrapper.setup(event.data.setup_info);
self.postMessage({
"event": "setup-complete"
});
break;
case "predict-row":
let message = await ai_wrapper.predict_row(event.data.latitude);
message.event = "result";
self.postMessage(message);
break;
case "end":
self.close();
break;
default:
throw new Error(`Error: Unknown event '${event.data.event}'`);
}
}
self.addEventListener("message", (event) => {
handle_message(event).catch((error) => {
console.error(error);
});
});