various options
Optional
worker?: string | WorkerConstructorThe worker class, not instantiated, or a path to the source code. If not provided, the client will use the service worker. If a string is provided, it'll instantiate a regular Worker
, not a SharedWorker
.
Example: "./worker.js"
See Worker (used by both dedicated workers and service workers), SharedWorker, and
the different worker types that exist
Optional
nodes?: numberthe number of workers to use for the server, defaults to navigator.hardwareConcurrency.
Optional
hooks?: Hooks<Procedures>Hooks to run on messages received from the server. See Hooks
Optional
loglevel?: "debug" | "info" | "warn" | "error"Maximum log level to use, defaults to "debug" (shows everything). "info" will not show debug messages, "warn" will only show warnings and errors, "error" will only show errors.
Optional
restartListener?: booleanIf true, will force the listener to restart even if it has already been started. You should probably leave this to false, unless you are testing and want to reset the client state.
Optional
localStorage?: Record<string, any>Define a in-memory localStorage with the given key-value pairs. Allows code called on the server to access localStorage (even though SharedWorkers don't have access to the browser's real localStorage)
a sw&rpc client instance. Each property of the procedures map will be a method, that accepts an input and an optional onProgress callback, see ClientMethod
An example of defining and using a client:
<script lang="ts">
import {resolve} from '$app/paths'
</script>
<nav>
<p>Single-node tests</p>
<ul>
<li><a href={resolve('/[worker]/', {worker: "service"})}>Using a service worker</a></li>
<li><a href={resolve('/[worker]/', {worker: "dedicated"})}>Using a dedicated worker</a></li>
<li><a href={resolve('/[worker]/', {worker: "shared"})}>Using a shared worker</a></li>
</ul>
<p>Multi-node tests</p>
<ul>
<li><a href="{resolve('/[worker]/parallel/', {worker: "service"})}?nodes=10">Using a service worker</a></li>
<li><a href="{resolve('/[worker]/parallel/', {worker: "dedicated"})}?nodes=10">Using a dedicated worker</a></li>
<li><a href="{resolve('/[worker]/parallel/', {worker: "shared"})}?nodes=10">Using a shared worker</a></li>
</ul>
</nav>
procedures the client will be able to call, see ProceduresMap