GoogleChromeLabs / GoogleChromeLabs/comlink

Class example not working

Open
#408 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
12.8k
Forks
435
PR merge metrics
No merged PRs in 30d

Description

I try to run the example 03 with class in my project:

```js
import * as Comlink from 'comlink';
import {
Game
} from "./src/index.js"

console.log("start 1");
async function init() {
console.log("start 2");
const MyClass = Comlink.wrap(new Worker("worker.js"));
console.log("start 3");
console.log(MyClass);
let worker = new MyClass();
console.log("start 4");
console.log(worker);
let game = new Game(worker);
console.log("start 5");
console.log(game);
}
init().catch(console.trace);

```

worker.js:

```js
import * as Comlink from 'comlink';
import("../../rust-src/pkg").then(wasm => {
wasm.init();
class MyClass {

constructor() {
console.log("Worker started");
}

request() {
return wasm.request()
}

chacha20poly1305_decrypt(key, noce, str) {
return wasm.chacha20poly1305_decrypt(key, noce, str)
}

chacha20poly1305_encrypt(key, noce, str) {
return wasm.chacha20poly1305_encrypt(key, noce, str)
}

aes_encrypt(str) {
return wasm.aes_encrypt(str)
}
hash(str) {
return wasm.hash(str)
}
}

Comlink.expose(MyClass);
});
```

But the await blocks the script as shown in the example. Is the example outdated or what is wrong?

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.