CodeSampleX

샘플

scheduler 0.25.0: unstable_ImmediatePriority

검증된 샘플 — npm scheduler 0.25.0: unstable_ImmediatePriority. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: unstable_ImmediatePriority is exported…

sha256:9a609dc2d925debc93aecf53d37234124e9285ae22968bbe7f35d57f1748b796

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

실행 증거

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

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

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

케이스

HOW
목표
verify scheduler.unstable_ImmediatePriority in pkg:npm/scheduler@0.25.0
패키지
심벌
  • scheduler.unstable_ImmediatePriority
환경
node 22.23.2
생성일
2026-08-21T02:45:29Z

컨트랙트

  1. unstable_ImmediatePriority is exported as a priority constant equal to 1
  2. unstable_runWithPriority executes a callback synchronously at unstable_ImmediatePriority level and restores previous priority
  3. unstable_wrapCallback binds a function to unstable_ImmediatePriority when wrapped within an immediate priority scope
  4. unstable_scheduleCallback schedules tasks with unstable_ImmediatePriority to execute ahead of lower priority tasks
  5. unstable_cancelCallback cancels a task scheduled with unstable_ImmediatePriority

파일

  • 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 scheduler.unstable_ImmediatePriority 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:
  - scheduler.unstable_ImmediatePriority

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:5b48f332d3edb7a3f7dfbaf37d05b62187945a898928766e3eed48c227160d2d","contract":["unstable_ImmediatePriority is exported as a priority constant equal to 1","unstable_runWithPriority executes a callback synchronously at unstable_ImmediatePriority level and restores previous priority","unstable_wrapCallback binds a function to unstable_ImmediatePriority when wrapped within an immediate priority scope","unstable_scheduleCallback schedules tasks with unstable_ImmediatePriority to execute ahead of lower priority tasks","unstable_cancelCallback cancels a task scheduled with unstable_ImmediatePriority"],"goal":"verify scheduler.unstable_ImmediatePriority in pkg:npm/scheduler@0.25.0","kind":"HOW","packages":["pkg:npm/scheduler@0.25.0"],"schemaVersion":1,"symbols":["scheduler.unstable_ImmediatePriority"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/scheduler@0.25.0"],"schemaVersion":1,"subject":"pkg:npm/scheduler@0.25.0","symbols":["scheduler.unstable_ImmediatePriority"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-scheduler-immediate-priority",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-scheduler-immediate-priority",
      "version": "1.0.0",
      "license": "MIT-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-immediate-priority",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room code sample for scheduler.unstable_ImmediatePriority in scheduler@0.25.0",
  "main": "src/index.js",
  "license": "MIT-0",
  "dependencies": {
    "scheduler": "0.25.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify scheduler.unstable_ImmediatePriority in pkg:npm/scheduler@0.25.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/scheduler@0.25.0"
  ],
  "symbols": [
    "scheduler.unstable_ImmediatePriority"
  ]
}
src/index.js
const scheduler = require('scheduler');

const {
  unstable_ImmediatePriority,
  unstable_UserBlockingPriority,
  unstable_NormalPriority,
  unstable_LowPriority,
  unstable_IdlePriority,
  unstable_getCurrentPriorityLevel,
  unstable_runWithPriority,
  unstable_wrapCallback,
  unstable_scheduleCallback,
  unstable_cancelCallback
} = scheduler;

/**
 * Execute a callback immediately with highest priority level (unstable_ImmediatePriority).
 *
 * @param {Function} callback - Function to execute synchronously with immediate priority.
 * @returns {*} Return value of the callback.
 */
function runImmediate(callback) {
  return unstable_runWithPriority(unstable_ImmediatePriority, callback);
}

/**
 * Wrap a function so it always executes with unstable_ImmediatePriority.
 *
 * @param {Function} callback - Function to wrap.
 * @returns {Function} Wrapped callback executing with immediate priority.
 */
function wrapImmediate(callback) {
  return unstable_runWithPriority(unstable_ImmediatePriority, () => {
    return unstable_wrapCallback(callback);
  });
}

/**
 * Schedule a task with immediate priority level.
 *
 * @param {Function} callback - Task callback to schedule.
 * @param {object} [options] - Scheduling options.
 * @returns {object} Scheduled task node.
 */
function scheduleImmediate(callback, options) {
  return unstable_scheduleCallback(unstable_ImmediatePriority, callback, options);
}

module.exports = {
  scheduler,
  unstable_ImmediatePriority,
  unstable_UserBlockingPriority,
  unstable_NormalPriority,
  unstable_LowPriority,
  unstable_IdlePriority,
  unstable_getCurrentPriorityLevel,
  unstable_runWithPriority,
  unstable_wrapCallback,
  unstable_scheduleCallback,
  unstable_cancelCallback,
  runImmediate,
  wrapImmediate,
  scheduleImmediate
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';

const require = createRequire(import.meta.url);
const {
  scheduler,
  unstable_ImmediatePriority,
  unstable_UserBlockingPriority,
  unstable_NormalPriority,
  unstable_LowPriority,
  unstable_IdlePriority,
  unstable_getCurrentPriorityLevel,
  unstable_runWithPriority,
  unstable_wrapCallback,
  unstable_scheduleCallback,
  unstable_cancelCallback,
  runImmediate,
  wrapImmediate,
  scheduleImmediate
} = require('../src/index.js');

async function testAll() {
  // 1. unstable_ImmediatePriority is exported as a priority constant equal to 1
  assert.equal(typeof scheduler, 'object', 'scheduler should be exported as an object');
  assert.equal(typeof unstable_ImmediatePriority, 'number', 'unstable_ImmediatePriority should be a number');
  assert.equal(unstable_ImmediatePriority, 1, 'unstable_ImmediatePriority value should equal 1');
  assert.equal(scheduler.unstable_ImmediatePriority, 1, 'scheduler.unstable_ImmediatePriority should equal 1');
  assert.equal(typeof runImmediate, 'function', 'runImmediate should be a function');
  assert.equal(typeof wrapImmediate, 'function', 'wrapImmediate should be a function');
  assert.equal(typeof scheduleImmediate, 'function', 'scheduleImmediate should be a function');

  // 2. unstable_runWithPriority executes a callback synchronously at unstable_ImmediatePriority level and restores previous priority
  const defaultPriority = unstable_getCurrentPriorityLevel();
  assert.equal(defaultPriority, unstable_NormalPriority, 'Default priority should be NormalPriority (3)');

  let recordedInsidePriority = null;
  const result = runImmediate(() => {
    recordedInsidePriority = unstable_getCurrentPriorityLevel();
    return 'priority-result';
  });

  assert.equal(recordedInsidePriority, unstable_ImmediatePriority, 'Priority inside runImmediate should be ImmediatePriority (1)');
  assert.equal(result, 'priority-result', 'runImmediate should return the value produced by callback');
  assert.equal(unstable_getCurrentPriorityLevel(), defaultPriority, 'Priority should be restored to default after runImmediate');

  // 3. unstable_wrapCallback binds a function to unstable_ImmediatePriority when wrapped within an immediate priority scope
  let callbackObservedPriority = null;
  const boundCallback = wrapImmediate(() => {
    callbackObservedPriority = unstable_getCurrentPriorityLevel();
  });

  // Call the wrapped callback from within a lower priority level
  unstable_runWithPriority(unstable_LowPriority, () => {
    boundCallback();
  });
  assert.equal(callbackObservedPriority, unstable_ImmediatePriority, 'Wrapped callback should execute with ImmediatePriority even when invoked from LowPriority');

  // 4. unstable_scheduleCallback schedules tasks with unstable_ImmediatePriority to execute ahead of lower priority tasks
  const executionOrder = [];
  await new Promise((resolve) => {
    unstable_scheduleCallback(unstable_LowPriority, () => {
      executionOrder.push('low');
      if (executionOrder.length === 3) resolve();
    });

    unstable_scheduleCallback(unstable_NormalPriority, () => {
      executionOrder.push('normal');
      if (executionOrder.length === 3) resolve();
    });

    scheduleImmediate(() => {
      executionOrder.push('immediate');
      if (executionOrder.length === 3) resolve();
    });
  });

  assert.deepEqual(
    executionOrder,
    ['immediate', 'normal', 'low'],
    'ImmediatePriority task should execute before NormalPriority and LowPriority tasks'
  );

  // 5. unstable_cancelCallback cancels a task scheduled with unstable_ImmediatePriority
  let cancelledRan = false;
  let companionRan = false;

  await new Promise((resolve) => {
    const taskToCancel = scheduleImmediate(() => {
      cancelledRan = true;
    });

    unstable_cancelCallback(taskToCancel);

    scheduleImmediate(() => {
      companionRan = true;
      resolve();
    });
  });

  assert.equal(cancelledRan, false, 'Cancelled immediate priority task should not have executed');
  assert.equal(companionRan, true, 'Companion task should have executed');

  console.log('All scheduler.unstable_ImmediatePriority contract tests passed successfully.');
}

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

오리진 시더

익명