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 APIMethod and callback plugin/handlerWeb Worker

You can communicate between a Web Worker and the main thread in either direction (or both) like so:

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

This plugin currently does not yet support other types of worker like Shared Workers or Service Workers.

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