You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

24 lines
660 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";
let instance1, instance2;
async function showState() {
alert(`instance1.counter = ${await instance1.counter},
instance2.counter = ${await instance2.counter}`);
}
async function init() {
const MyClass = Comlink.wrap(new Worker("worker.js"));
instance1 = await new MyClass();
instance2 = await new MyClass(42);
await showState();
await instance1.increment();
await instance2.increment(23);
await showState();
}
init();
</script>