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

icetea-queue

v0.1.10

Published

A simple queue implementation

Readme

icetea-queue

A simple, lightweight TypeScript queue implementation for processing items concurrently across multiple slots. Supports both synchronous and asynchronous executors with completion tracking.

Installation

npm install icetea-queue

Quick Start

import { Queue } from "icetea-queue";

// Create a queue with 3 parallel slots
const queue = new Queue<number>(3);

// Set an executor function (called for each item)
queue.setExecutor(async (item, allData) => {
  console.log(`Processing: ${item}`);
  return true; // return truthy to continue to next item
});

// Provide data to process
queue.setData([1, 2, 3, 4, 5, 6]);

// Handle completion
queue.onCompleted((result) => {
  console.log("All done!", result);
  // { status: true, completed: 6 }
});

// Start processing
queue.execute();

API

Queue<T>(roomSize: number)

Creates a new queue with the specified number of parallel slots.

| Parameter | Type | Description | | ---------- | -------- | ----------------------------------------- | | roomSize | number | Number of parallel processing slots/rooms |

Methods

setData(data: T[]): this

Sets the data to be processed and distributes it across the available slots in a round-robin fashion. Returns this for chaining.

queue.setData([0, 1, 2, 3, 4, 5]);
// Slot distribution with roomSize=3:
//   Slot 0: [0, 3]
//   Slot 1: [1, 4]
//   Slot 2: [2, 5]

setExecutor(executor: Function): void

Sets the callback function that processes each item. The executor receives the current item and the full dataset.

// Sync executor
queue.setExecutor((item, allData) => {
  // process item
  return true; // truthy → proceed to next item, falsy → stop
});

// Async executor
queue.setExecutor(async (item, allData) => {
  await someAsyncWork(item);
  return true;
});
  • Throws Error if executor is not a function.

execute(): void

Starts processing all items across the queue slots. The executor must be set before calling this method.

  • Throws Error if no executor has been set.
  • Does nothing if data is empty.

onCompleted(callback: Function): void

Registers a callback that fires when all items have been processed.

queue.onCompleted((result) => {
  console.log(result.status); // true
  console.log(result.completed); // total items processed
});
  • Throws Error if callback is not a function.

isPromise(callback: Function): boolean

Checks whether a given callback is an async function.

queue.isPromise(async () => {}); // true
queue.isPromise(() => {}); // false
queue.isPromise(null); // false

Behavior

  • Round-robin distribution: Data is evenly distributed across the available slots.
  • Sequential within slots: Each slot processes its items one after another.
  • Parallel across slots: All slots process concurrently.
  • Completion callback: Fires once every item across all slots has been processed.
  • Auto-reset: After all items are processed, internal state resets automatically.
  • Falsy return stops progression: If the executor returns a falsy value, that slot stops processing further items.

Example

Processing with completion tracking

import { Queue } from "icetea-queue";

const queue = new Queue<string>(2);

queue.onCompleted(({ status, completed }) => {
  console.log(`Completed ${completed} items: ${status}`);
});

queue.setExecutor(async (item) => {
  const result = await fetch(`https://api.example.com/${item}`);
  return result.ok;
});

queue.setData(["a", "b", "c", "d"]);
queue.execute();

License

MIT