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…

sha256:216d91d91e968222fd88085bfbc9d41ef2424cfeac222cad6936d625e0e8bcd0

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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);
});

オリジンシーダー

匿名