ProvenPin Install

p-map concurrency-limited async mapping: working versions (tested 2026-10-15)

Map an async iterator with p-map while capping concurrency and preserving result order.

passed1 passed · 0 failed2026-10-15 20:57 UTC
Status
passed
Last passed
2026-10-15 20:57 UTC
Tests
1 / 1
Language
TypeScript
Runtime
node v22.23.3
pinned versions3
p-map@7.1.1@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 38805962781

The code

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

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

export async function doubleAll(values: number[], concurrency: number, onStart: (n: number) => void) {
  let inflight = 0;
  let maxInflight = 0;
  const result = await pMap(
    values,
    async (n) => {
      inflight += 1;
      maxInflight = Math.max(maxInflight, inflight);
      onStart(inflight);
      await new Promise((r) => setTimeout(r, 20));
      inflight -= 1;
      return n * 2;
    },
    { concurrency },
  );
  return { result, maxInflight };
}
test/map.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { doubleAll } from "../src/map.ts";

test("preserves order and respects concurrency", async () => {
  const peaks: number[] = [];
  const { result, maxInflight } = await doubleAll([1, 2, 3, 4, 5, 6], 2, (n) => peaks.push(n));
  assert.deepEqual(result, [2, 4, 6, 8, 10, 12]);
  assert.ok(maxInflight <= 2);
  assert.ok(Math.max(...peaks) <= 2);
});

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.