LoRaWAN-Signal-Mapping/client_src/js/Worker/AI.worker.mjs
Starbeamrainbowlabs 52d4f4fb38 Bugfix the new web worker.
Web workers + Tensorflow + Rollup = pain. I think I might blog about 
it....
2019-07-25 18:56:59 +01:00

36 lines
733 B
JavaScript

"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);
});
});