swarpc - v0.14.0
    Preparing search index...

    Function Client

    • Type Parameters

      Parameters

      • procedures: Procedures

        procedures the client will be able to call, see ProceduresMap

      • options: {
            worker?: string | WorkerConstructor;
            nodes?: number;
            hooks?: Hooks<Procedures>;
            loglevel?: "debug" | "info" | "warn" | "error";
            restartListener?: boolean;
            localStorage?: Record<string, any>;
        } = {}

        various options

        • Optionalworker?: string | WorkerConstructor

          The 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

        • Optionalnodes?: number

          the number of workers to use for the server, defaults to navigator.hardwareConcurrency.

        • Optionalhooks?: Hooks<Procedures>

          Hooks to run on messages received from the server. See Hooks

        • Optionalloglevel?: "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.

        • OptionalrestartListener?: boolean

          If 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.

        • OptionallocalStorage?: 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)

      Returns SwarpcClient<Procedures>

      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>