Standard Toolkit
Packages@accelint/temporal

Overview

@accelint/temporal provides temporal utilities for JavaScript applications. The library focuses on clock-aligned timing operations that synchronize with system clock boundaries, preventing drift in repeated timer operations.

Installation

pnpm add @accelint/temporal

Usage

// Import from root (all exports)
import { setClockInterval, setClockTimeout } from '@accelint/temporal';

// Import from sub-modules
import { setClockInterval, setClockTimeout } from '@accelint/temporal/timers';

Available Exports

Timers

FunctionDescription
setClockIntervalExecute a callback repeatedly at specified intervals, starting at the next clock second boundary
setClockTimeoutExecute a callback once after a specified delay, starting from the next clock second boundary

Examples

Example: Clock display

import { setClockInterval } from '@accelint/temporal';

function startClock(element: HTMLElement) {
  const cleanup = setClockInterval(() => {
    element.textContent = new Date().toLocaleTimeString();
  }, 1000);
  
  return cleanup;
}

// Start the clock
const cleanup = startClock(document.getElementById('clock'));

// Stop when done
cleanup();

Example: Scheduled task

import { setClockTimeout } from '@accelint/temporal';

function scheduleNotification(message: string, delayMs: number) {
  const cleanup = setClockTimeout(() => {
    console.log(message);
  }, delayMs);
  
  return cleanup;
}

// Schedule for 5 seconds from next clock second
const cancel = scheduleNotification('Task complete!', 5000);

// Cancel if needed
cancel();

On this page