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

@promistream/fork-select

v0.1.0

Published

General-purpose forking stream

Downloads

7

Readme

@promistream/fork-select

A general-purpose forking Promistream. Lets you fork a pipeline into an arbitrary number of downstream forks, and divide values among them based on an arbitrary predicate function. Can be used directly, or as a basis for other types of forking streams.

Stream characteristics:

  • Promistream version: 0
  • Stream type: Fork
  • Supports parallelization: Yes (order-preserving)
  • Buffering: Unbounded; one internal buffer per fork, buffer only fills as needed to unblock other forks
  • Fork distribution strategy: User-specified

Example

A runnable version of this example is included in the package as example.js.

"use strict";

const pipe = require("@promistream/pipe");
const debug = require("@promistream/debug");
const fromIterable = require("@promistream/from-iterable");
const forkSelect = require("@promistream/fork-select");
const collect = require("@promistream/collect");

(async () => {
	let [ a, b ] = await pipe([
		fromIterable([ 0, 0, 0, 1, 1, 2 ]),
		debug("source"),
		forkSelect(2, (value) => {
			return value % 2;
		})
	]).read();

	setTimeout(async () => {
		try {
			let bResults = await pipe([
				b,
				// debug("pipeline B"),
				collect()
			]).read();

			console.log({ bResults }); // { bResults: [ 1, 1 ] }
		} catch (error) {
			console.error("error from B", error);
		}
	}, 1000);

	try {
		let aResults = await pipe([
			a,
			// debug("pipeline A"),
			collect()
		]).read();

		console.log({ aResults }); // { aResults: [ 0, 0, 0, 2 ] }
	} catch (error) {
		console.error("error from A", error);
	}
})();

API

forkSelect(forkCount, select)

Creates a new forkSelect stream. Note that only the value assignment is configurable; errors (including EndOfStream and Aborted markers) are always broadcast to all forks.

  • forkCount: Required. The amount of forks to create.
  • select: Required. The predicate callback to determine which fork a given value should be sent to. Receives the value as its argument, and is expected to return (a Promise of) the index of the fork to send it to. An array of fork indexes may also be specified to send the value to multiple forks.