title | description |
---|---|
Worker |
Simple Web Workers registration and communication. |
Simple Web Workers registration and communication.
<script>
import { worker } from "@sveu/browser"
const { data, post, error, cleanup } = worker("/path/to/worker.js")
</script>
<script>
import { worker } from "@sveu/browser"
let value = "svelte"
const { data, post, error, cleanup } = worker("/worker.js")
$: console.log($error)
</script>
<div class="flex flex-col space-y-9 mx-9 mt-9 text-center">
<h1>Data: {$data}</h1>
<input
type="text"
id="message"
bind:value="{value}" />
<button on:click="{() => post(value)}">Send</button>
<br />
<button on:click="{() => cleanup()}">Stop</button>
</div>
Name | Description | Type | Required |
---|---|---|---|
url | Worker path url | string |
No(if worker is provided ) |
worker | Worker function or Worker instance | Worker or WorkerFn |
No(if url is provided ) |
Name | Description | Type |
---|---|---|
data | Data from the worker | Readable<any > |
error | Error from the worker | Readable<any > |
wk | Worker instance | Readable<Worker > |
cleanup | Function to terminate the worker | () => void |
post | Function to send data to the worker | (message: any, transfer: Transferable[]): void or (message: any, options?: StructuredSerializeOptions): void |