npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

roro.js

v1.0.12

Published

## Description

Downloads

20

Readme

roro.js

Description

roro.js is an RPC toolkit that works with web workers, web sockets, iframes and web rtc.

roro.js let you provide and use functions across message based channels, e.g., you can implement a function in a web worker and call it from the main script.

under the hood, function calls are translated to messages which are passed via the messaging API of the underlying channel (postMessage and onmessage for web workers, send and onmessage for web sockets, etc.).

roro.js let you optimize the way messages are transferred in two manners: batching and serializing.

Batching

Priorities

Each exposed function has two priorities: Call Priority and Return Priority. The value of these priorities is one of:

  • None (-2)
  • Immediate (-1)
  • High (0)
  • Animation (1000 / 60)
  • Low (100)

Except for None and Immediate, the priority is specified in milliseconds. None is only available for return priority.

The default priority is Immediate

Immediate means that each function call will be translated to a unique message passing. This behavior might be inefficient since message passing via postMessage is much more time consuming than function calls.

For this reason, you can specify for each function a priority. When the the priority is 0 or more, the message representing the function call will be appended to a queue which will be serialized and passed in a single call to postMessage after the timeout. For example, a loop with 10 calls with an Immediate priority will result in 10 postMessages. The same loop with a High priority will result in 1 postMessage. Increasing the value of the priority will let more calls join the queue before the timeout is reached.

Although different calls might have different priorities, the order of calls is always guarantied to be kept. For that reason, if a higher priority call (one with a lower timeout value) is made after a lower priority call, when the queue is drained and the messages are serialized and posted, the lower priority call will be executed before it's timeout. For example, an Immediate call will always drain the queue and makes any pending call to be executed.

The None priority is useful for cases when a function doesn't return a value. Sometimes in these cases, caller is not interested in waiting for the promise to be resolved. Setting the return priority to None will resolve the promise on the calling side immediately and will not post a message for the return value.

Serializing

roro.js supports 3 types of serializers:

  • Native
  • JSON
  • Binary

The Native serializer uses the browser structured clone algorithm. It can be user with web workers and iframes.

The JSON serializer uses JSON.stringify and JSON.parse and is therefore suitable for all types of channels.

The Binary serializer lets you write custom serialization and serialize the function parameters and return value to an ArrayBuffer and then post a message with that array as a transferable object

API

MessageRPC

WebWorkerChannel

NativeSerializer

Installation

yarn add roro.js

Usage

import { MessageRPC } from 'roro.js'