GoogleChromeLabs / GoogleChromeLabs/comlink
Worker call to main ("the other way around") doesn't work in node?
- Dominant language
- TypeScript
- Stars
- 12.8k
- Forks
- 435
- PR merge metrics
- No merged PRs in 30d
Description
I've tried to implement the solution in https://github.com/GoogleChromeLabs/comlink/issues/506#issuecomment-753457080, but that doesn't seem to work in node.
Because nodejs doesn't have a "self" context, I've tried using "globalThis" instead, but when I run it it still throws a "self is not defined" error (from the expose function in comlink).
In my `main.ts` file I've tried:
```ts
const worker = new Worker(filename);
const obj = Comlink.wrap(nodeEndpoint(worker)) as unknown as Engine;
Comlink.expose(this.engine, nodeEndpoint(worker));
```
and in my worker file I have tried:
```ts
Comlink.wrap(globalThis) as unknown as Engine;
```
I suspect the issue is with `Comlink.expose(this.engine, nodeEndpoint(worker));` and the nodeEndpoint part but I can't figure it out.
Contributor guide
Assessment
This issue has not been assessed yet.