Starbeamrainbowlabs
52d4f4fb38
Web workers + Tensorflow + Rollup = pain. I think I might blog about it....
36 lines
733 B
JavaScript
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);
|
|
});
|
|
});
|