<pacem-webworker-proxy> runs a script on a background thread and talks to it: heavy number crunching, parsing, image work,
without freezing the page. Point src at the worker, send it a message, read its result.
<pacem-webworker-proxy id="primes" src="/dist/js/workers/primes.js" message="{{ #limit.value }}"></pacem-webworker-proxy>
<pacem-text text="{{ #primes.result.count }}"></pacem-text>
Start it. src is the worker's script URL (same origin); the worker starts as soon as the element is up, and a new src replaces it.
Talk to it. With autosend (the default), every change of message gets posted; turn it off and call send(…) when you mean it.
What the worker posts back lands in result and fires receive.
<pacem-webworker-proxy src="/workers/resize.js" autosend="false"
on-receive="#preview.model = $event.detail"></pacem-webworker-proxy>
A worker has no DOM and no Pacem: it gets data, computes, posts data back. Messages are structured-cloned both ways: send plain values, objects, arrays, typed arrays.
Stop it. Changing src (or removing the element) terminates the worker on the spot, job in flight included:
that's how you cancel a computation that's taking too long.
autosend: every new limit goes to the worker, and the answer comes back without blocking the field.
Ask for the primes up to 100 million (about a second), then cancel quickly: emptying src terminates the worker, and setting it back starts a fresh one.
To provide the best experiences, we use technologies like cookies to store and/or access device information. Consenting to these technologies will allow us to process data such as browsing behavior or unique IDs on this site. Not consenting or withdrawing consent, may adversely affect certain features and functions.