CodeSampleX

Пример

scheduler 0.25.0: unstable_scheduleCallback

Проверенный пример — npm scheduler 0.25.0: unstable_scheduleCallback. Контракт выполнен на node 22 · linux debian/x64 · docker и пройден.

sha256:8ac5e07497d9d5091714cee039886021afee195292eb8efabad9d5bffa9983b3

Эта сеть предлагает одно: образец, который собирается. Она запустила его в песочнице и сохранила подписанную квитанцию. Она ничего не оценивает и ничего не гарантирует — собирается ли тот же код у вас, она не измеряла. Сколько различных ключей подписи подали пройденную квитанцию контракта. Один — только автор; больше одного — значит, кто-то ещё тоже собрал. Ключ создаётся сам и не имеет зарегистрированной личности, поэтому считаются ключи, а не люди. MIT-0

Свидетельства выполнения

Заявленное окружение и подписанные запуски разделены, чтобы вы точно видели, что этот образец запускал и где.

Основа свидетельства
Подписанный контракт пройден
Квитанции проверки
1
Ключи подписи, собравшие его
1
Заявленная среда linux 24 · ubuntu · glibc 2.39 x64 npm

Среды запусков проверки

Окружение Контракт Этапы Запуск
node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2…
2026-09-02

Кейс

HOW
Цель
verify unstable_scheduleCallback in pkg:npm/scheduler@0.25.0
Пакеты
Символы
  • unstable_scheduleCallback
Создан
2026-09-02T14:24:31Z

Контракт

  1. unstable_scheduleCallback is exported as a function
  2. unstable_scheduleCallback schedules a task with priorityLevel and returns a task descriptor
  3. unstable_scheduleCallback computes expirationTime according to priority timeout
  4. unstable_scheduleCallback offsets startTime when delay option is provided
  5. unstable_scheduleCallback generates sequential task IDs for new tasks

Файлы

  • PROMPT.md
  • csx.json
  • package-lock.json
  • package.json
  • spec.json
  • src/index.js
  • 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 unstable_scheduleCallback in pkg:npm/scheduler@0.25.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/scheduler@0.25.0
Demonstrate these symbols/APIs:
  - unstable_scheduleCallback

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:6e90286abe4018be44abe0255f922b7a1d3c2134d5b36bec941f3356b094e4d3","contract":["unstable_scheduleCallback is exported as a function","unstable_scheduleCallback schedules a task with priorityLevel and returns a task descriptor","unstable_scheduleCallback computes expirationTime according to priority timeout","unstable_scheduleCallback offsets startTime when delay option is provided","unstable_scheduleCallback generates sequential task IDs for new tasks"],"goal":"verify unstable_scheduleCallback in pkg:npm/scheduler@0.25.0","kind":"HOW","packages":["pkg:npm/scheduler@0.25.0"],"schemaVersion":1,"symbols":["unstable_scheduleCallback"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/scheduler@0.25.0"],"schemaVersion":1,"subject":"pkg:npm/scheduler@0.25.0","symbols":["unstable_scheduleCallback"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-scheduler-schedule-callback",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-scheduler-schedule-callback",
      "version": "1.0.0",
      "dependencies": {
        "scheduler": "0.25.0"
      }
    },
    "node_modules/scheduler": {
      "version": "0.25.0",
      "resolved": "https://registry.npmjs.org/scheduler/-/scheduler-0.25.0.tgz",
      "integrity": "sha512-xFVuu11jh+xcO7JOAGJNOXld8/TcEHK/4CituBUeUb5hqxJLj9YuemAEuvm9gQ/+pgXYfbQuqAkiYu+u7YEsNA==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-scheduler-schedule-callback",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification of scheduler unstable_scheduleCallback",
  "main": "src/index.js",
  "dependencies": {
    "scheduler": "0.25.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify unstable_scheduleCallback in pkg:npm/scheduler@0.25.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/scheduler@0.25.0"
  ],
  "symbols": [
    "unstable_scheduleCallback"
  ]
}
src/index.js
const scheduler = require('scheduler');

/**
 * Schedules a callback with a specified priority level and optional settings.
 * @param {number} priority - The priority level constant.
 * @param {Function} callback - The callback function to execute.
 * @param {object} [options] - Options such as { delay: number }.
 * @returns {object} The scheduled task object.
 */
function scheduleWithPriority(priority, callback, options) {
  return scheduler.unstable_scheduleCallback(priority, callback, options);
}

/**
 * Schedules an immediate priority task.
 * @param {Function} callback - The callback function.
 * @returns {object} The scheduled task object.
 */
function scheduleImmediate(callback) {
  return scheduler.unstable_scheduleCallback(
    scheduler.unstable_ImmediatePriority,
    callback
  );
}

/**
 * Schedules a normal priority task.
 * @param {Function} callback - The callback function.
 * @param {object} [options] - Scheduling options.
 * @returns {object} The scheduled task object.
 */
function scheduleNormal(callback, options) {
  return scheduler.unstable_scheduleCallback(
    scheduler.unstable_NormalPriority,
    callback,
    options
  );
}

/**
 * Schedules a delayed task with normal priority.
 * @param {Function} callback - The callback function.
 * @param {number} delayMs - Delay in milliseconds.
 * @returns {object} The scheduled task object.
 */
function scheduleDelayed(callback, delayMs) {
  return scheduler.unstable_scheduleCallback(
    scheduler.unstable_NormalPriority,
    callback,
    { delay: delayMs }
  );
}

module.exports = {
  scheduler,
  scheduleWithPriority,
  scheduleImmediate,
  scheduleNormal,
  scheduleDelayed
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  scheduler,
  scheduleWithPriority,
  scheduleImmediate,
  scheduleNormal,
  scheduleDelayed
} = require('../src/index.js');

// 1. unstable_scheduleCallback is exported as a function
assert.equal(
  typeof scheduler.unstable_scheduleCallback,
  'function',
  'unstable_scheduleCallback must be a function'
);

// 2. unstable_scheduleCallback schedules a task with priorityLevel and returns a task descriptor
{
  const noop = () => {};
  const task = scheduleNormal(noop);

  assert.ok(task, 'Task descriptor must be returned');
  assert.equal(typeof task.id, 'number', 'Task must have a numeric id');
  assert.equal(task.callback, noop, 'Task callback must match provided function');
  assert.equal(
    task.priorityLevel,
    scheduler.unstable_NormalPriority,
    'Task priority level must match NormalPriority'
  );
  assert.equal(typeof task.startTime, 'number', 'Task startTime must be numeric');
  assert.equal(typeof task.expirationTime, 'number', 'Task expirationTime must be numeric');
}

// 3. unstable_scheduleCallback computes expirationTime according to priority timeout
{
  const noop = () => {};
  const normalTask = scheduleWithPriority(scheduler.unstable_NormalPriority, noop);
  const immediateTask = scheduleWithPriority(scheduler.unstable_ImmediatePriority, noop);
  const lowTask = scheduleWithPriority(scheduler.unstable_LowPriority, noop);
  const userBlockingTask = scheduleWithPriority(scheduler.unstable_UserBlockingPriority, noop);
  const idleTask = scheduleWithPriority(scheduler.unstable_IdlePriority, noop);

  // Immediate priority timeout: -1ms
  assert.equal(immediateTask.expirationTime, immediateTask.startTime - 1);
  // User blocking priority timeout: 250ms
  assert.equal(userBlockingTask.expirationTime, userBlockingTask.startTime + 250);
  // Normal priority timeout: 5000ms
  assert.equal(normalTask.expirationTime, normalTask.startTime + 5000);
  // Low priority timeout: 10000ms
  assert.equal(lowTask.expirationTime, lowTask.startTime + 10000);
  // Idle priority timeout: 1073741823ms (maxSigned31BitInt)
  assert.equal(idleTask.expirationTime, idleTask.startTime + 1073741823);
}

// 4. unstable_scheduleCallback offsets startTime when delay option is provided
{
  const noop = () => {};
  const delayMs = 500;
  const beforeTime = scheduler.unstable_now();
  const delayedTask = scheduleDelayed(noop, delayMs);
  const afterTime = scheduler.unstable_now();

  assert.ok(
    delayedTask.startTime >= beforeTime + delayMs &&
    delayedTask.startTime <= afterTime + delayMs,
    'Delayed task startTime must be offset by delay amount'
  );
  assert.equal(
    delayedTask.sortIndex,
    delayedTask.startTime,
    'Delayed task sortIndex must equal startTime'
  );
}

// 5. unstable_scheduleCallback generates sequential task IDs for new tasks
{
  const noop = () => {};
  const task1 = scheduleNormal(noop);
  const task2 = scheduleNormal(noop);

  assert.equal(
    task2.id,
    task1.id + 1,
    'Subsequent tasks must receive incremented task IDs'
  );
}

console.log('Contract assertions for unstable_scheduleCallback passed.');

Исходный сидер

аноним