@mys-x/m-rpc
TypeScript icon, indicating that this package has built-in type declarations

0.12.2 • Public • Published

m-rpc

jsr-version npm-version npm-minzip docs stars license

coverage workflow-ci workflow-release

A message based RPC library.

Usage

basic

import { MRpc } from "@mys-x/m-rpc"; // or "jsr:@mys/m-rpc"

function add(a: number, b: number) {
  return a + b;
}

// The port can be a MessagePort, a WebSocket, a Worker, or a WorkerGlobalScope
const { port1, port2 } = new MessageChannel();
const rpc1 = new MRpc(port1);
const rpc2 = new MRpc(port2);

rpc1.defineLocalFn("add", add);
await rpc2.callRemoteFn<typeof add>("add", [1, 2]); // 3

License

MIT License © 2024-PRESENT mys1024

/@mys-x/m-rpc/

    Package Sidebar

    Install

    npm i @mys-x/m-rpc

    Weekly Downloads

    13

    Version

    0.12.2

    License

    MIT

    Unpacked Size

    50.5 kB

    Total Files

    7

    Last publish

    Collaborators

    • mys1024