ProvenPin Install

p-queue bounded concurrency: working versions (tested 2026-10-16)

Enqueue async jobs with p-queue at concurrency 2, assert no more than two run at once, and exercise pause, start and onIdle offline.

passed3 passed · 0 failed2026-10-16 15:21 UTC
Status
passed
Last passed
2026-10-16 15:21 UTC
Tests
3 / 3
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
p-queue@10.0.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false
npm test
test environment
node v22.23.3
linux 6.17.0-1022-azure
x64
runner: github-actions 38923127324

The code

Exactly the files that passed. Your agent can pull them with get_recipe("p-queue-concurrency") (install), or see them on GitHub.

package.json
{
  "name": "p-queue-concurrency",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "p-queue": "10.0.0"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/queue.ts
import PQueue from "p-queue";

export type AsyncJob<T> = () => Promise<T>;

export interface TrackedQueue {
  queue: PQueue;
  run<T>(job: AsyncJob<T>): Promise<T>;
  readonly active: number;
  readonly maxActive: number;
}

export function createTrackedQueue(concurrency = 2): TrackedQueue {
  const queue = new PQueue({ concurrency });
  let active = 0;
  let maxActive = 0;

  async function run<T>(job: AsyncJob<T>): Promise<T> {
    const value = await queue.add(async () => {
      active += 1;
      maxActive = Math.max(maxActive, active);
      try {
        return await job();
      } finally {
        active -= 1;
      }
    });
    return value as T;
  }

  return {
    queue,
    run,
    get active() {
      return active;
    },
    get maxActive() {
      return maxActive;
    },
  };
}
test/queue.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import PQueue from "p-queue";
import { createTrackedQueue } from "../src/queue.ts";

const delay = (ms: number): Promise<void> =>
  new Promise((resolve) => setTimeout(resolve, ms));

test("runs at most the configured concurrency", async () => {
  const tracked = createTrackedQueue(2);

  const jobs = Array.from({ length: 6 }, (_, i) =>
    tracked.run(async () => {
      await delay(10);
      return i;
    })
  );

  const results = await Promise.all(jobs);
  await tracked.queue.onIdle();

  assert.deepEqual(results, [0, 1, 2, 3, 4, 5]);
  assert.equal(tracked.maxActive, 2);
});

test("pause holds jobs until start", async () => {
  const queue = new PQueue({ concurrency: 2 });
  const started: number[] = [];
  queue.pause();

  const jobs = [1, 2, 3].map((n) =>
    queue.add(async () => {
      started.push(n);
      await delay(5);
    })
  );

  await delay(5);
  assert.deepEqual(started, []);

  queue.start();
  await queue.onIdle();
  await Promise.all(jobs);

  assert.deepEqual(started, [1, 2, 3]);
});

test("onIdle resolves once all jobs finish", async () => {
  const queue = new PQueue({ concurrency: 1 });
  let finished = 0;

  void queue.add(async () => {
    await delay(5);
    finished += 1;
  });
  void queue.add(async () => {
    await delay(5);
    finished += 1;
  });

  await queue.onIdle();

  assert.equal(finished, 2);
  assert.equal(queue.size, 0);
  assert.equal(queue.pending, 0);
});

Connect to ProvenPin

Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.

terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp

Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.