CodeSampleX

Ejemplo

es-toolkit 1.50.0: delay

Muestra verificada para npm es-toolkit 1.50.0: delay. El contrato se ejecutó en node 22 · linux alpine/x64 · docker y pasó: delay returns a Promise that…

sha256:c40cef11f1a785d6172fd7c88e338c3320c224264a00636368979db21fe6d0a6

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node linux 24 · ubuntu · glibc 2.39 x64 node node npm

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify es-toolkit.delay in pkg:npm/es-toolkit@1.50.0
Paquetes
Símbolos
  • es-toolkit.delay
Entorno
node
Creado
2026-08-27T23:53:58Z

Contrato

  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

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 de origen

anónimo