Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@ironiumstudios/rpc-node

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ironiumstudios/rpc-node

Type-safe communication between message ports from Node.js worker_threads module

  • 2.0.7
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
134
increased by1118.18%
Maintainers
1
Weekly downloads
 
Created
Source

@ironiumstudios/rpc-node

Type-safe communication between message ports from Node.js worker_threads module.

NOTE:

this project is licensed under the company wexond, i am only forking this project to modernize it and i wish for no trouble from the wexond devs or redbrick

NPM NPM

Installation

$ npm install --save @ironiumstudios/rpc-node @ironiumstudios/rpc-core

Quick start

Here's an example of communication from the main thread to a worker_thread:

  • Create a file that is imported in both the worker_thread and the main thread, for example ping-pong.ts:
import { WorkerChannel } from '@ironiumstudios/rpc-node';

export interface PingPongService {
  ping(): string;
}

export const pingPongChannel = new WorkerChannel<PingPongService>('ping-pong');
  • Code for your worker_thread:
import { RpcWorkerHandler } from '@ironiumstudios/rpc-node';
import { PingPongService, pingPongChannel } from './ping-pong';

class PingPongHandler implements RpcWorkerHandler<PingPongService> {
  // Equivalent of |parentPort.on('message')|
  ping(): string {
    return 'pong';
  }
}

// |parentPort| is the default value for the |messagePort| parameter in |getReceiver|.
pingPongChannel.getReceiver().handler = new PingPongHandler();
  • Code for the main thread:
import { resolve } from 'path';
import { Worker } from 'worker_threads';

import { pingPongChannel } from './ping-pong';

const worker = new Worker('path/to/worker.js');
const pingPongService = pingPongChannel.getInvoker(worker);

(async () => {
  console.log(await pingPongService.ping()); // Prints `pong`.
})();

More examples

Documentation

WIP

FAQs

Package last updated on 24 May 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc