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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@kderbyma/braid

v1.0.2

Published

A Language-Agnostic Co-routine Framework - weave independent asynchronous strands into synchronized cords

Readme

🧶 Braid

A Language-Agnostic Co-routine Framework for weaving independent asynchronous "strands" into synchronized cords.

Installation

npm install braid
# or
yarn add braid
# or
pnpm add braid

Usage

import { Braid, Loom, Fiber, Tension, fromArray, counter, interval, just } from 'braid';

// Create Fibers from various sources
const letters = fromArray(['A', 'B', 'C'], 'letters');
const numbers = fromArray([1, 2, 3], 'numbers');

// Weave them together with a Braid
const braid = new Braid([letters, numbers]);

// Collect all emitted tuples
const results = await Loom.collect(braid);
// → [["A",1], ["B",2], ["C",3]]

// Or use in for await loops
for await (const [letter, number] of braid) {
  console.log(`${letter}: ${number}`);
}

Core Concepts

Fiber

A Fiber wraps any AsyncGenerator and gives it an identity. It's the atom of the Braid.

const fiber = new Fiber(async function* () {
  yield 1;
  yield 2;
  yield 3;
}, { name: 'myFiber' });

Fibers have built-in combinators:

  • map(fn) - Transform values
  • filter(pred) - Filter by predicate
  • take(n) - Limit to n values
  • prepend(seed) - Emit seed before starting

Braid

A Braid weaves N Fibers together with different tension modes:

// TIGHT (default) - Lock-step synchronization
const tight = new Braid([fiberA, fiberB]);

// LOOSE - Non-blocking, uses last known value
const loose = new Braid([fastFiber, slowFiber], { 
  tension: Tension.Loose 
});

// FRAYED - Strict fault intolerance
const frayed = new Braid([fiberA, fiberB], { 
  tension: Tension.Frayed 
});

Loom

The Loom is the executor that runs a Braid to completion.

// Run with handler
await Loom.run(braid, (value, index) => {
  console.log(`[${index}]`, value);
});

// Collect to array
const results = await Loom.run(braid);

// Run multiple concurrently
await Loom.runAll([
  [braidA, handlerA],
  [braidB, handlerB],
]);

API Reference

Classes

  • Fiber<T> - Single async strand wrapper
  • Braid<Ts> - Woven collection of Fibers
  • Loom - Executor for running Braids

Enums

  • Tension.Tight - Atomic lock-step (default)
  • Tension.Loose - Non-blocking, cached values
  • Tension.Frayed - Strict fault intolerance

Combinators

  • merge(...fibers) - Fan-in, unordered
  • zip(a, b) - Binary zip into pairs
  • chain(...sources) - Sequential interleaving
  • partition(fiber, pred) - Split by predicate

Factory Functions

  • fromArray(values) - Create from array
  • counter(start, intervalMs) - Infinite counter
  • interval(value, intervalMs) - Periodic emitter
  • just(value) - Single value

Error Classes

  • BraidError - Base error
  • BraidTimeoutError - Timeout error for Frayed mode

License

MIT