UNPKG

comlink

Version:
22 lines (17 loc) 635 B
<!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 SharedWorker("worker.js"); /** * SharedWorkers communicate via the `postMessage` function in their `port` property. * Therefore you must use the SharedWorker's `port` property when calling `Comlink.wrap`. */ const obj = Comlink.wrap(worker.port); alert(`Counter: ${await obj.counter}`); await obj.inc(); alert(`Counter: ${await obj.counter}`); } init(); </script>