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

rxport

v0.0.1

Published

RxPort is a library for baking web workers with RxJS

Downloads

2

Readme

pu# RxPort

Introduction

The RxPort library provides a simple and efficient way to create communication channels between different threads in your application using RxJS.

Installation

npm install rxport rxjs

Usage

To create a observable between threads, you need something that will share between threads information about you stream. Class RxPort provides a simple way to do that.

const myObservablePort = new RxPort<string, string>('MyObservable');

Now you can use this port to create a observable between threads.

In one thread you need to create producer part of the observable:

// SharedWorker
const myProducer = myObservablePort.createProducer(self);

Now you can use this producer to response to requests from other threads:

myProducer.subscribe((request: string) => {
    console.log(response); // 'Hi Alis'
    return of('Hi Bob');
});

In other thread you need to create consumer part of the observable:

// Main thread
const request = myObservablePort.createRequest(new SharedWorker('shared-worker.js'));

Now you can use this request to create a observable that will send requests to other thread:

request('Hi Alis').subscribe((response: string) => {
    console.log(response); // 'Hi Bob'
});

Destroying producer

If you want to destroy producer, you need to call destroy method:

import {interval} from "rxjs";

const destroy = myProducer.subscribe(() => interval(1000));

destroy();

If you destroy producer, while there are active requests, they will receive Abort Error;

import {AbortConnectionMessage} from "rxport";

request('...').subscribe({
    error: (error) => {
        if (error.message === AbortConnectionMessage) {
            console.log('Producer was aborted');
        }
    }
});

Lose connection

If you lose connection between threads, you will receive Lose Connection Error:

import {LoseConnectionMessage} from "rxport";

request('...').subscribe({
    error: (error) => {
        if (error.message === LoseConnectionMessage) {
            console.log('Connection was lost');
        }
    }
});

You can meet this error, if create observable from SharedWorker to Window(browser tab), and close window.

Advanced usage

You can create a observable not only between threads, actually you can create a stream any object that implements MessagePort interface.

const channel = new MessageChannel();
const rxPort = new RxPort<string, string>('...');

const producer = rxPort.createProducer(channel.port1);
const request = rxPort.createRequest(channel.port2);