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

breadline-ts

v1.1.2

Published

Queue manager for async operations

Readme

Breadline

npm version npm downloads License

Breadline is a robust, type-safe asynchronous task queue for Node.js. It helps you manage concurrency, enforce rate limits, and schedule tasks with priorities, all while retaining full control over execution flow.

Features

  • Concurrency Control: Limit the number of tasks running in parallel.
  • Rate Limiting: Enforce strict execution limits over time windows (e.g., 10 reqs / 1 sec).
  • Priority Support: Schedule urgent tasks to run before others.
  • Pluggable Queues: Use the default Priority Queue or switch to Binary Max-Heap for performance.
  • AbortSignal Support: Cancel queued or running tasks using standard AbortController.
  • Event-Driven: Hook into lifecycle events like empty, idle, or rateLimited.
  • Zero Dependencies: (Almost) zero — only eventemitter3 for efficient event handling.
  • TypeScript: Written in TypeScript with full type definitions.

Installation

npm install breadline-ts

Usage

Basic Usage (Concurrency Control)

Limit concurrent execution to prevent overwhelming resources.

import { Breadline } from "breadline";

// Create a queue allowing 2 concurrent tasks
const queue = new Breadline({ concurrency: 2 });

const task = (id: number) => async () => {
    console.log(`Start ${id}`);
    await new Promise(r => setTimeout(r, 1000));
    console.log(`End ${id}`);
    return id;
};

// Add tasks
queue.add(task(1));
queue.add(task(2));
queue.add(task(3)); // Will wait until 1 or 2 finishes

Rate Limiting

Ensure you don't exceed API rate limits (e.g., 5 requests per second).

const queue = new Breadline({
    interval: 1000, // 1 second window
    intervalCap: 5  // Max 5 tasks per window
});

for (let i = 0; i < 20; i++) {
    queue.add(async () => {
        await fetch("https://api.example.com/data");
    });
}

Prioritization

Process important tasks first, even if they were added later.

const queue = new Breadline({ concurrency: 1 });

queue.add(async () => console.log("Low priority"), { priority: 0 });
queue.add(async () => console.log("High priority"), { priority: 10 });
queue.add(async () => console.log("Medium priority"), { priority: 5 });

// Output:
// High priority
// Medium priority
// Low priority

Custom Queues

You can swap the internal queue implementation for better performance or custom behavior.

import { Breadline, BinaryMaxHeap } from "breadline";

// Use BinaryMaxHeap for potentially faster priority handling in very large queues
const queue = new Breadline({
    queue: BinaryMaxHeap
});

Cancellation (AbortSignal)

Cancel tasks that are waiting in the queue or currently running (if supported by the task).

const controller = new AbortController();
const queue = new Breadline();

queue.add(
    async ({ signal }) => {
        const response = await fetch("https://example.com", { signal });
        return response.json();
    },
    { signal: controller.signal }
).catch(err => console.log("Task aborted:", err));

// Cancel the task
controller.abort();

API Reference

new Breadline(options?)

Creates a new queue instance.

| Option | Type | Default | Description | | :--- | :--- | :--- | :--- | | concurrency | number | Infinity | Max concurrent tasks. | | interval | number | 1 | Time window in milliseconds for rate limiting. | | intervalCap | number | Infinity | Max tasks allowed per interval. | | immediate | boolean | true | If true, tasks start immediately. If false, call start(). | | queue | class | PriorityQueue | Custom queue implementation (e.g. BinaryMaxHeap). |

Methods

  • add(task, options?): Adds a task to the queue. Returns a Promise that resolves with the task result.
    • task: ({ signal }) => Promise<T>
    • options: { priority?: number, signal?: AbortSignal, id?: string }
  • addMany(tasks, options?): Adds multiple tasks.
  • pause(): Pauses processing of new tasks.
  • start(): Resumes processing.
  • clear(): Removes all queued tasks.
  • prioritize(id, priority): Updates the priority of a waiting task.
  • onEmpty(): Returns a Promise that resolves when the queue becomes empty.
  • onIdle(): Returns a Promise that resolves when the queue is empty AND all running tasks have finished.

Events

The queue emits the following events:

  • "add": A task was added.
  • "active": A task started executing.
  • "done": A task completed successfully.
  • "error": A task failed.
  • "empty": The queue is empty (but tasks may be running).
  • "idle": The queue is empty and no tasks are running.
  • "rateLimited": Rate limit has been reached.
  • "rateLimitCleared": Rate limit has reset.

License

ISC