CodeSampleX

샘플

p-limit 2.3.0

검증된 샘플 — npm p-limit 2.3.0. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: pLimit creates a limiter that restricts concurrency to the specified…

sha256:216d91d91e968222fd88085bfbc9d41ef2424cfeac222cad6936d625e0e8bcd0

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 windows 10 x64 npm vm

검증 실행 환경

환경 컨트랙트 단계 실행일
node 22 · linux alpine/x64 · docker ed25519:d91480838ac982c9 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1
2026-08-20

케이스

HOW
목표
verify pkg:npm/p-limit@2.3.0
패키지
생성일
2026-08-19T22:57:03Z

컨트랙트

  1. pLimit creates a limiter that restricts concurrency to the specified limit
  2. runWithLimit executes tasks concurrently up to the specified limit
  3. activeCount and pendingCount track running and queued tasks
  4. clearQueue discards pending tasks that have not started execution

파일

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • sample.mjs
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

PROMPT.md
Clean-room public code sample — generation instructions

Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.

A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.

Goal: verify pkg:npm/p-limit@2.3.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/p-limit@2.3.0

Rules:
  - One focused purpose; the smallest project that proves the goal.
  - Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
  - Pin every dependency with a lockfile so resolution is reproducible.
  - No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
  - No personal names, emails, company names, or project identifiers of any kind.
  - No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
  - Keep it under 200 files and 256KB packed.
csx.json
{"case":{"caseId":"case:sha256:d52bdca73158231e4015007d106f0ae588771e0fd89505c6ceffdb94dfe2b81d","contract":["pLimit creates a limiter that restricts concurrency to the specified limit","runWithLimit executes tasks concurrently up to the specified limit","activeCount and pendingCount track running and queued tasks","clearQueue discards pending tasks that have not started execution"],"goal":"verify pkg:npm/p-limit@2.3.0","kind":"HOW","packages":["pkg:npm/p-limit@2.3.0"],"schemaVersion":1,"symbols":["p-limit","p-limit.activeCount","p-limit.pendingCount","p-limit.clearQueue"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","ecosystem":"npm","os":"windows","osVersionBucket":"10","packageManager":"npm","schemaVersion":1,"virtualization":"vm"},"license":"MIT-0","packages":["pkg:npm/p-limit@2.3.0"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample",
      "version": "1.0.0",
      "dependencies": {
        "p-limit": "2.3.0"
      }
    },
    "node_modules/p-limit": {
      "version": "2.3.0",
      "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-2.3.0.tgz",
      "integrity": "sha512-//88mFWSJx8lxCzwdAABTJL2MyWB12+eIY7MDL2SqLmAkeKU9qxRvWuSyTjm3FUmpBEMuFfckAIqEaVGUDxb6w==",
      "dependencies": {
        "p-try": "^2.0.0"
      },
      "engines": {
        "node": ">=6"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/p-try": {
      "version": "2.2.0",
      "resolved": "https://registry.npmjs.org/p-try/-/p-try-2.2.0.tgz",
      "integrity": "sha512-R4nPAVTAU0B9D35/Gk3uJf/7XYbQcyohSKdvAxIRSNghFl4e71hVoGnBNQz9cWaXxO2I10KTC+3jMdvvoKw6dQ==",
      "engines": {
        "node": ">=6"
      }
    }
  }
}
package.json
{
  "name": "sample",
  "version": "1.0.0",
  "type": "module",
  "dependencies": {
    "p-limit": "2.3.0"
  }
}
sample.mjs
import pLimit from 'p-limit';

/**
 * Creates a concurrency limiter with the specified limit.
 * @param {number} concurrency
 * @returns {Function}
 */
export function createLimiter(concurrency) {
  return pLimit(concurrency);
}

/**
 * Runs a list of tasks with a concurrency limit.
 * @param {Array<() => Promise<any>>} tasks
 * @param {number} concurrency
 * @returns {Promise<any[]>}
 */
export async function runWithLimit(tasks, concurrency) {
  const limit = pLimit(concurrency);
  return Promise.all(tasks.map((task) => limit(task)));
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/p-limit@2.3.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/p-limit@2.3.0"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import pLimit from 'p-limit';
import { createLimiter, runWithLimit } from '../sample.mjs';

async function testConcurrencyLimit() {
  const limit = createLimiter(2);
  let active = 0;
  let maxActive = 0;

  const tasks = Array.from({ length: 6 }, (_, i) => async () => {
    active++;
    if (active > maxActive) {
      maxActive = active;
    }
    await new Promise((resolve) => setTimeout(resolve, 30));
    active--;
    return i;
  });

  const results = await Promise.all(tasks.map((t) => limit(t)));
  assert.deepEqual(results, [0, 1, 2, 3, 4, 5], 'all tasks should complete in order');
  assert(maxActive <= 2, `max concurrent tasks (${maxActive}) should not exceed limit (2)`);
  console.log('Contract 1 passed: concurrency limit respected');
}

async function testRunWithLimit() {
  const tasks = [
    async () => 10,
    async () => 20,
    async () => 30
  ];
  const results = await runWithLimit(tasks, 2);
  assert.deepEqual(results, [10, 20, 30], 'runWithLimit should return mapped task results');
  console.log('Contract 2 passed: runWithLimit works');
}

async function testCountsAndQueue() {
  const limit = pLimit(1);
  let resolveFirst;
  const firstPromise = new Promise((resolve) => {
    resolveFirst = resolve;
  });

  const p1 = limit(() => firstPromise);
  const p2 = limit(() => Promise.resolve('second'));
  const p3 = limit(() => Promise.resolve('third'));

  assert.equal(limit.activeCount, 1, 'activeCount should be 1');
  assert.equal(limit.pendingCount, 2, 'pendingCount should be 2');

  limit.clearQueue();
  assert.equal(limit.pendingCount, 0, 'pendingCount should be 0 after clearQueue');

  resolveFirst('first');
  const res1 = await p1;
  assert.equal(res1, 'first', 'first task should complete');
  console.log('Contract 3 & 4 passed: activeCount, pendingCount, and clearQueue verified');
}

async function main() {
  await testConcurrencyLimit();
  await testRunWithLimit();
  await testCountsAndQueue();
  console.log('All contracts passed successfully.');
}

main().catch((err) => {
  console.error('Contract test failed:', err);
  process.exit(1);
});

오리진 시더

익명