RPC Docs.

Prim+RPC is prerelease software. It may be unstable and functionality may change prior to full release.

IPC Plugins and Handlers

These are the currently supported plugins and handlers for Prim+RPC. This guide is slightly different from Client Plugins and Server Plugins in that the client and server may be on the same machine. For each framework below, all of the possible plugins for that framework will be given.

Table of Contents

Web Workers

ForPlugin TypeTransport Type
Web Workers, Shared WorkersMethod and callback plugin/handlerWeb Worker

You can communicate between a Web Worker and the main thread in either direction, or both, like so (both Dedicated and Shared Workers are supported):

worker.ts

import { createPrimServer } from "@doseofted/prim-rpc"
import { createMethodHandler, createCallbackHandler, jsonHandler } from "@doseofted/prim-rpc-plugins/web-worker"
const methodHandler = createMethodHandler({ worker: self })
const callbackHandler = createCallbackHandler({ worker: self })
createPrimServer({ methodHandler, callbackHandler, jsonHandler })

index.ts

import { createPrimClient } from "@doseofted/prim-rpc"
import { createMethodPlugin, createCallbackPlugin, jsonHandler } from "@doseofted/prim-rpc-plugins/web-worker"
// You may use a Dedicated Worker or a Shared Worker (both are supported)
const worker = new Worker(new URL("./worker", import.meta.url), { type: "module" })
const methodPlugin = createMethodPlugin({ worker })
const callbackPlugin = createCallbackPlugin({ worker })
const client = createPrimClient({ methodPlugin, callbackPlugin, jsonHandler })

Note that the web worker plugin has a jsonHandler export. This is just a helper utility that will disable JSON handling. JSON handling should be disabled because Web Workers will use structured cloning instead which is far more powerful. Of course, you can always override the JSON handler to anything that you'd like if you can forgo structured cloning.

Vitest / Jest

ForPlugin TypeTransport Type
Testing (Vitest, Jest, etc.)Method and callback plugin/handlerLocal (Same File)

It's easy to use Prim+RPC in a single file by communicating over a generic event handler. Use like so:

index.ts

import { createPrimClient, createPrimServer, testing } from "@doseofted/prim-rpc"
const plugins = testing.createPrimTestingPlugins()
const { callbackHandler, methodHandler } = plugins
const server = createPrimServer({ callbackHandler, methodHandler })
const { methodPlugin, callbackPlugin } = plugins
const client = createPrimClient({ callbackPlugin, methodPlugin })

Note that the results of createPrimTestingPlugins() must be passed to both the Prim+RPC server and client because they are linked during setup.

Child Process

ForPlugin TypeTransport Type
NodeMethod and callback plugin/handlerChild Process

Unavailable (planned)

Electron

ForPlugin TypeTransport Type
ElectronMethod and callback plugin/handlerElectron

Unavailable (planned)

Prim+RPC: a project by Ted Klingenberg

Dose of Ted

Anonymous analytics collected with Ackee