19 lines
493 B
HTML
19 lines
493 B
HTML
<!DOCTYPE html>
|
|
|
|
<script type="module">
|
|
import * as Comlink from "https://unpkg.com/comlink/dist/esm/comlink.mjs";
|
|
// import * as Comlink from "../../../dist/esm/comlink.mjs";
|
|
|
|
async function init() {
|
|
const worker = new Worker("worker.js");
|
|
// WebWorkers use `postMessage` and therefore work with Comlink.
|
|
const obj = Comlink.wrap(worker);
|
|
|
|
alert(`Counter: ${await obj.counter}`);
|
|
await obj.inc();
|
|
alert(`Counter: ${await obj.counter}`);
|
|
}
|
|
|
|
init();
|
|
</script>
|