Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

IPC

Manav Rathib28e8c2fb45e
diff --git a/desktop/src/main/services/ml-util-test.ts b/desktop/src/main/services/ml-util-test.ts
index 684b782c4b..2dd68e2ffb 100644
--- a/desktop/src/main/services/ml-util-test.ts
+++ b/desktop/src/main/services/ml-util-test.ts
@@ -1,10 +1,33 @@
-console.log("in utility process");
+import log from "../log";
+import { ensure, wait } from "../utils/common";
-process.parentPort.once("message", (e) => {
- console.log("got message in utility process", e);
- const [port] = e.ports;
+log.debug(() => "Started ML worker process");
- port?.on("message", (e2) => {
- console.log("got message on port in utility process", e2);
+process.parentPort.once("message", (e) => {
+ const port = ensure(e.ports[0]);
+ port.on("message", (event) => {
+ void handleMessage(event.data).then((response) => {
+ if (response) port.postMessage(response);
+ });
});
});
+
+/** Our hand-rolled IPC handler and router */
+const handleMessage = async (m: unknown) => {
+ if (m && typeof m == "object" && "type" in m) {
+ switch (m.type) {
+ case "foo":
+ if ("a" in m && typeof m.a == "string") return await foo(m.a);
+ break;
+ }
+ }
+
+ log.info("Ignoring unexpected message", m);
+ return undefined;
+};
+
+const foo = async (a: string) => {
+ console.log("got message foo with argument", a);
+ await wait(0);
+ return a.length;
+};