ProvenPin Install

async-mutex serialize critical section access: working versions (tested 2026-10-15)

Protect a shared counter with async-mutex so concurrent tasks update it without races.

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

The code

Exactly the files that passed. Your agent can pull them with get_recipe("async-mutex-critical-section") (install), or see them on GitHub.

package.json
{
  "name": "async-mutex-critical-section",
  "private": true,
  "type": "module",
  "scripts": {
    "test": "node --import tsx --test test/*.test.ts"
  },
  "dependencies": {
    "async-mutex": "0.5.0"
  },
  "devDependencies": {
    "@types/node": "26.6.5",
    "tsx": "4.23.15"
  }
}
src/locked.ts
import { Mutex } from "async-mutex";

export function createLockedCounter() {
  const mutex = new Mutex();
  let value = 0;
  return {
    async increment() {
      return mutex.runExclusive(async () => {
        const next = value + 1;
        await Promise.resolve();
        value = next;
        return value;
      });
    },
    get() {
      return value;
    },
  };
}
test/locked.test.ts
import { test } from "node:test";
import assert from "node:assert/strict";
import { createLockedCounter } from "../src/locked.ts";

test("mutex serializes concurrent increments", async () => {
  const counter = createLockedCounter();
  await Promise.all(Array.from({ length: 50 }, () => counter.increment()));
  assert.equal(counter.get(), 50);
});

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.