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

relays.js

v0.1.2

Published

Asynchronous objects that is a hybrid of observer, emitter and Promise.

Downloads

3

Readme

relays.js

A library for controlling asynchronous flow of execution

NPM

HitCount

codecov Build Status Inline docs

Known Vulnerabilities devDependencies Status

What are Relays

Relays are a representation of an asynchronous callback which can receive inputs when a relay accepts inputs, process those inputs and return an output. You can imagine it as a hybrid of an observer and an observable, except that Relays won't start executing the callback if the inputs received does not match the required number of connected inputs.

For example,

let AndGate = new Relay((a, b) => a && b);
let AndGateInputA = new Relay(x => typeof x === "boolean" && x);
let AndGateInputB = new Relay(x => typeof x === "boolean" && x);

AndGateInputA.connectTo(AndGate);
AndGateInputB.connectTo(AndGate);

AndGate.pass(x => console.log("The result is " + x));

AndGateInputA.receive(true);
AndGateInputB.receive(true);

The code represents a simple implementation of AND gate through the use of Relays. AndGateInputA and AndGateInputB are what we call "input Relays", they are connected to an arbitrary amount of Relays (in this case, we only have one output relay, the AndGate), and whenever they receive an input, they are going to process it with their callbacks (x => typeof x === "boolean" && x) after which they are going to emit it to their output relay. Input relays can receive, process and pass the information at an arbitrary time.

The output Relay, on the other hand, waits for its input Relays to pass information to it until such time it can process the information and pass it to its output Relay. Output Relays don't know when will the inputs arrive, until such time, the inputs already received will be pending (which means, Output Relays can receive the inputs, but they cannot process it until the necessary amount of inputs are met), so both codes below do the same thing.

AndGate.receive(true, true);
AndGateInputA.receive(true);
AndGateInputB.receive(true);

The sequence of inputs depends on the arrival time. Relays don't know which inputs came from which input Relays, what it only knows is what are the input values.

Once all input Relays have been executed, and passed the resulting information to their output Relays, the output Relay will then start processing the received inputs. In our example, once both AndGateInputs have received an input, their respective callbacks are then executed to process the inputs, in which they will pass their result to the AndGate. The AndGate will then receive the two inputs, process it and pass it to an anonymous Relay, x => console.log("The result is " + x).

As a summary, think of Relays as an individual representation of a Promise.all except that it is reusable and can wait for itself to resolve (Relays can connect to itself). For AI enthusiasts, think of Relays like a Perceptron model except that there is no backpropagation and no calibration.

Usage

NPM

npm i relays.js

CDN

<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/relays.js/dist/index.min.js"></script>

Examples

Build

Clone the repo then run:

npm install

which will install dependencies. You can then run:

npm run build

which build the NodeJS module, the browser-version (with minified) of the source, the docs, the test and coverages.

License

MIT License

Copyright (c) 2019 Alexis Munsayac

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.