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

worker-rpc

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

worker-rpc

A simple RPC layer for communicating with web workers and over other transports

  • 0.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
820K
decreased by-57.89%
Maintainers
1
Weekly downloads
 
Created

What is worker-rpc?

The worker-rpc package is a lightweight and efficient library for facilitating RPC (Remote Procedure Call) style communication between web workers and the main thread in a web environment. It simplifies the process of sending and receiving messages, making it easier to manage asynchronous tasks and parallel processing in web applications.

What are worker-rpc's main functionalities?

Creating an RPC Provider

This code sample demonstrates how to create an RPC provider in the main thread. The RpcProvider is initialized with a function that sends messages to the worker. The worker's onmessage handler is set to dispatch incoming messages through the RpcProvider.

const { RpcProvider } = require('worker-rpc');
const rpcProvider = new RpcProvider(message => worker.postMessage(message));
worker.onmessage = event => rpcProvider.dispatch(event.data);

Creating an RPC Handler

This code sample shows how to set up an RPC handler inside a worker. It creates an RpcProvider that sends messages back to the main thread. The 'calculate' RPC handler is registered to multiply a number by 2, demonstrating how to handle specific tasks.

const { RpcProvider } = require('worker-rpc');
const rpcProvider = new RpcProvider(message => postMessage(message));
onmessage = event => rpcProvider.dispatch(event.data);
rpcProvider.registerRpcHandler('calculate', data => data.num * 2);

Other packages similar to worker-rpc

Keywords

FAQs

Package last updated on 19 May 2019

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