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 🙏

© 2025 – Pkg Stats / Ryan Hefner

instant-relay

v3.0.0

Published

An opinionated library for asynchronous communication between nodes. Focuses on backpressure management, simplicity, performance.

Readme

instant-relay

instant-relay is a library of primitives for backpressure-aware, intra-process asynchronous communication. It provides foundational building blocks that may be combined to form any desired topology.

How to use

instant-relay exports three primitive classes: BusToOne, BusToMany and Subscriber.

import { BusToOne, ButToMany, Subscriber } from 'instant-relay';

The Bus abstract class

A bus is a strongly-typed communication channel which multiple consumers may subscribe to and which multiple producers may publish to. Each bus is typed according to the kinds of messages that may be published to it and to the kind of values that may be returned by subscribers as a result of processing each message.

All bus classes extends the abstract Bus class. Bus instances are backpressure-aware; the Bus.prototype.publish() method returns a promise that resolves when it is safe to publish additional messages.

Buses may be terminated via the Bus.prototype.destroy() method.

The BusToOne class

The BusToOne class implements a bus that dispatches published messages to only one of its subscribers, selected according to the specified strategy.

The promise returned by the BusToOne.prototype.publish() method resolves to the value returned by the (one) subscriber that processed the message.

const number_bus = new BusToOne<number, string>();
const as_string: string = await number_bus.publish(Math.random());

Subscriber selector functions can be passed to the BusToOne constructor via the selector option:

const selector: BusToOne.Selector = { pick: subs => subs[0] };
new BusToOne<number, string>({ selector });

Available strategies:

| default | class | description | | --- | --- | --- | || BusToOne.FirstSelector | returns the first subscriber in the array | | X | BusToOne.RoundRobinSelector | cycles through subscriber | || BusToOne.RandomSelector | returns a randomly-selected subscriber | || BusToOne.LowestLagSelector | returns the subscriber with the lowest lag |

The concurrency constructor option can be used to set the max. amount of concurrent dispatches to subscribers.

The BusToMany class

The BusToMany class implements a bus that dispatches published messages to some or all of its subscribers, selected according to the specified strategy.

The promised returned by the BusToMany.prototype.publish() method resolves to an array of all the values returned by the (multiple) subscribers that processed the message.

const number_bus = new BusToOne<number, string>();
const as_string: string[] = await number_bus.publish(Math.random());

Subscriber selector functions can be passed to the BusToMany constructor via the selector option:

const selector: BusToMany.Selector = { pick: subs => subs.slice(1) };
new BusToMany<number, string>({ selector });

Available strategies:

| default | class | description | | --- | --- | --- | | X | BusToMany.AllSelector | returns all subscribers in the array |

The concurrency constructor option can be used to set the max. amount of concurrent dispatches to subscribers.

The Subscriber class

The Subscriber class may be used to create subscribers to one or more Bus instances out of a single handler function. The TS compiler will automatically infer the type of the message passed to the handler function based on the provided Bus instances.

const number_bus = new BusToOne<number>();
const boolean_bus = new BusToOne<boolean>();

const subscriber = Subscriber.create([number_bus, boolean_bus], async (message) => {
  // This will make the TS compiler throw an error
  // as the type of message is `number | boolean`
  // and must be narrowed further before treating
  // it as a number.
  message + 2;
});

Subscribers may be terminated via the Subscriber.prototype.destroy() method.

The concurrency constructor option can be used to set the max. amount of messages being processed at any one time.

License

Licensed under MIT.