ProvenPin Install

p-queue priority async task queue: working versions (tested 2026-10-15)

Schedule async tasks with p-queue using concurrency limits and priority ordering, covering pause/start and size helpers offline.

passed2 passed · 0 failed2026-10-15 16:03 UTC
Status
passed
Last passed
2026-10-15 16:03 UTC
Tests
2 / 2
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 38764699834

The code

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

package.json
{
  "name": "p-queue-priority",
  "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/jobs.ts
import PQueue from "p-queue";

export type Job = { id: string; priority?: number; work: () => Promise<string> };

export function createJobQueue(concurrency = 2) {
  const queue = new PQueue({ concurrency });
  const results: string[] = [];

  return {
    add(job: Job) {
      return queue.add(
        async () => {
          const value = await job.work();
          results.push(value);
          return value;
        },
        { priority: job.priority ?? 0 },
      );
    },
    pause() {
      queue.pause();
    },
    start() {
      queue.start();
    },
    async onIdle() {
      await queue.onIdle();
    },
    size() {
      return queue.size;
    },
    results() {
      return [...results];
    },
  };
}
test/jobs.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { createJobQueue } from "../src/jobs.ts";

test("runs higher priority jobs first when concurrency is 1", async () => {
  const q = createJobQueue(1);
  q.pause();
  const low = q.add({
    id: "low",
    priority: 1,
    work: async () => {
      await new Promise((r) => setTimeout(r, 5));
      return "low";
    },
  });
  const high = q.add({
    id: "high",
    priority: 10,
    work: async () => "high",
  });
  q.start();
  await Promise.all([low, high]);
  await q.onIdle();
  assert.deepEqual(q.results(), ["high", "low"]);
});

test("respects concurrency", async () => {
  const q = createJobQueue(2);
  let active = 0;
  let peak = 0;
  const mk = (id: string) =>
    q.add({
      id,
      work: async () => {
        active++;
        peak = Math.max(peak, active);
        await new Promise((r) => setTimeout(r, 25));
        active--;
        return id;
      },
    });
  await Promise.all([mk("a"), mk("b"), mk("c")]);
  assert.ok(peak <= 2);
  assert.equal(q.results().length, 3);
});

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.