CodeSampleX

Exemple

es-toolkit 1.50.0: delay

Échantillon vérifié pour npm es-toolkit 1.50.0: delay. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:c40cef11f1a785d6172fd7c88e338c3320c224264a00636368979db21fe6d0a6

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
1
Clés de signature qui l’ont compilé
1
Environnement déclaré node linux 24 · ubuntu · glibc 2.39 x64 node node npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5…
2026-08-27

Cas

HOW
Objectif
verify es-toolkit.delay in pkg:npm/es-toolkit@1.50.0
Paquets
Symboles
  • es-toolkit.delay
Environnement
node
Créé
2026-08-27T23:53:58Z

Contrat

  1. delay returns a Promise that resolves with undefined after the given duration
  2. delay is exported identically from the package root and es-toolkit/promise subpath
  3. delay cancels the pending timer and rejects with an AbortError when the provided AbortSignal is aborted during execution
  4. delay rejects immediately with an AbortError when the AbortSignal is already aborted prior to invocation
  5. compat delay invokes the callback function after the wait duration with supplied arguments and returns a timer id
  6. compat delay throws a TypeError when the first argument is not a function

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

NOTES.md
# es-toolkit delay API Behavior and Verification

### What search_known_solution answered
- `search_known_solution` returned `NO_SAFE_MATCH` for verifying `es-toolkit.delay` in `pkg:npm/es-toolkit@1.50.0`.
- This sample proves the runtime contract and cancellation semantics for `delay` in `es-toolkit@1.50.0`.

### Release
- Package: `es-toolkit`
- Version: `1.50.0` (pinned in `package.json` and `package-lock.json`)

### Verified Behaviors

1. **Modern Promise-Based Delay (`es-toolkit`, `es-toolkit/promise`)**:
   - `delay(ms)` returns a `Promise<void>` that resolves with `undefined` after `ms` milliseconds.
   - It can be imported from the package root `es-toolkit` or from `es-toolkit/promise`.

2. **AbortSignal Cancellation Support**:
   - `delay(ms, { signal })` accepts an optional `AbortSignal`.
   - If `controller.abort()` is called while the delay is in progress, the active timer is cleared and the promise rejects with an `AbortError` (subclass of `DOMException`).
   - If `signal` is already aborted prior to calling `delay`, the promise immediately rejects with an `AbortError` without starting a timer.

3. **Lodash Compatibility Delay (`es-toolkit/compat`)**:
   - `es-toolkit/compat` exports a Lodash-compatible `delay(func, wait, ...args)` that accepts a callback function and delay duration in milliseconds, returning a timer ID.
   - Throws `TypeError: Expected a function` if the first argument is not a callable function.
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 es-toolkit.delay in pkg:npm/es-toolkit@1.50.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/es-toolkit@1.50.0
Demonstrate these symbols/APIs:
  - es-toolkit.delay

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:73553476f69b0436a1ca523ad6c3640765ac1f5b83ed3b6f7f3ae1011c662a98","contract":["delay returns a Promise that resolves with undefined after the given duration","delay is exported identically from the package root and es-toolkit/promise subpath","delay cancels the pending timer and rejects with an AbortError when the provided AbortSignal is aborted during execution","delay rejects immediately with an AbortError when the AbortSignal is already aborted prior to invocation","compat delay invokes the callback function after the wait duration with supplied arguments and returns a timer id","compat delay throws a TypeError when the first argument is not a function"],"goal":"verify es-toolkit.delay in pkg:npm/es-toolkit@1.50.0","kind":"HOW","packages":["pkg:npm/es-toolkit@1.50.0"],"schemaVersion":1,"symbols":["es-toolkit.delay"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"node","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","runtime":"node","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/es-toolkit@1.50.0"],"schemaVersion":1,"subject":"pkg:npm/es-toolkit@1.50.0","symbols":["es-toolkit.delay"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "npm-es-toolkit-v1",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "npm-es-toolkit-v1",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "es-toolkit": "1.50.0"
      }
    },
    "node_modules/es-toolkit": {
      "version": "1.50.0",
      "resolved": "https://registry.npmjs.org/es-toolkit/-/es-toolkit-1.50.0.tgz",
      "integrity": "sha512-OyZKhUVvEep9ITEiwHn8GKnMRQIVqoSIX7WnRbkWgJkllCujilqP2rD0u979tkl8wqyc8ICwlc1UBVv/Sl1G6w==",
      "license": "MIT",
      "workspaces": [
        "docs",
        "benchmarks",
        "tests/types"
      ]
    }
  }
}
package.json
{
  "name": "npm-es-toolkit-v1",
  "version": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "es-toolkit": "1.50.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify es-toolkit.delay in pkg:npm/es-toolkit@1.50.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/es-toolkit@1.50.0"
  ],
  "symbols": [
    "es-toolkit.delay"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import { delay, AbortError } from 'es-toolkit';
import { delay as promiseDelay } from 'es-toolkit/promise';
import { delay as compatDelay } from 'es-toolkit/compat';

// 1. delay resolves after elapsed time
{
  const start = Date.now();
  const res = await delay(20);
  const elapsed = Date.now() - start;
  assert.strictEqual(res, undefined);
  assert.ok(elapsed >= 15, `Expected elapsed time >= 15ms, got ${elapsed}ms`);
}

// 2. delay from es-toolkit/promise is identical to standard export
{
  const res = await promiseDelay(10);
  assert.strictEqual(res, undefined);
}

// 3. delay is cancellable via AbortSignal during execution
{
  const controller = new AbortController();
  const timeoutId = setTimeout(() => controller.abort(), 10);
  
  await assert.rejects(
    async () => {
      await delay(500, { signal: controller.signal });
    },
    (err) => {
      assert.ok(err instanceof AbortError);
      assert.ok(err instanceof DOMException);
      assert.strictEqual(err.message, 'The operation was aborted');
      return true;
    }
  );
  clearTimeout(timeoutId);
}

// 4. delay rejects immediately if AbortSignal is already aborted
{
  const controller = new AbortController();
  controller.abort();

  await assert.rejects(
    async () => {
      await delay(100, { signal: controller.signal });
    },
    (err) => {
      assert.ok(err instanceof AbortError);
      assert.ok(err instanceof DOMException);
      return true;
    }
  );
}

// 5. es-toolkit/compat delay invokes callback after wait with arguments and returns timer id
{
  let called = false;
  let receivedArgs = [];
  
  const timerId = compatDelay(
    (a, b) => {
      called = true;
      receivedArgs = [a, b];
    },
    20,
    'foo',
    'bar'
  );

  assert.ok(timerId !== undefined);
  await delay(40);
  assert.strictEqual(called, true);
  assert.deepStrictEqual(receivedArgs, ['foo', 'bar']);
}

// 6. es-toolkit/compat delay throws TypeError if first argument is not a function
{
  assert.throws(
    () => compatDelay('not a function', 10),
    {
      name: 'TypeError',
      message: 'Expected a function',
    }
  );
}

Seeder d'origine

anonyme