ProvenPin Install

p-limit concurrent async job pool: working versions (tested 2026-10-15)

Cap parallel async work with p-limit, tracking in-flight count and collecting results in input order 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-limit@7.3.3@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-limit-concurrency") (install), or see them on GitHub.

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

export async function mapLimited<T, R>(
  items: T[],
  concurrency: number,
  fn: (item: T, index: number) => Promise<R>,
): Promise<R[]> {
  const limit = pLimit(concurrency);
  return Promise.all(items.map((item, i) => limit(() => fn(item, i))));
}

export function createPool(concurrency: number) {
  const limit = pLimit(concurrency);
  return {
    run<T>(fn: () => Promise<T>) {
      return limit(fn);
    },
    active() {
      return limit.activeCount;
    },
    pending() {
      return limit.pendingCount;
    },
  };
}
test/pool.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { mapLimited, createPool } from "../src/pool.ts";

test("never exceeds concurrency", async () => {
  let active = 0;
  let peak = 0;
  const results = await mapLimited([1, 2, 3, 4, 5], 2, async (n) => {
    active++;
    peak = Math.max(peak, active);
    await new Promise((r) => setTimeout(r, 20));
    active--;
    return n * 2;
  });
  assert.deepEqual(results, [2, 4, 6, 8, 10]);
  assert.ok(peak <= 2);
});

test("tracks active and pending counts", async () => {
  const pool = createPool(1);
  const a = pool.run(async () => {
    await new Promise((r) => setTimeout(r, 40));
    return "a";
  });
  const b = pool.run(async () => "b");
  await new Promise((r) => setTimeout(r, 5));
  assert.equal(pool.active(), 1);
  assert.equal(pool.pending(), 1);
  assert.deepEqual(await Promise.all([a, b]), ["a", "b"]);
});

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.