Skip to content

@jsvision/ui / runSpinner

Function: runSpinner()

runSpinner(frame, opts): () => void

Defined in: ui/src/feedback/run-spinner.ts:49

Advance frame by one every intervalMs, using the injectable one-shot timer (re-armed each tick).

Parameters

frame

Signal<number>

The caller-owned frame signal to advance (the same one handed to the Spinner).

opts

RunSpinnerOptions

intervalMs (default 80) + the timer seam.

Returns

stop() — clears the pending timer and stops advancing; safe to call more than once.

() => void

Example

ts
import { Group, Spinner, runSpinner, signal, type TimerSeam } from '@jsvision/ui';

const frame = signal(0);
const g = new Group();
g.add(new Spinner({ frame, label: 'Working…' }));

// Any object satisfying `TimerSeam` works — wrap the platform timer functions directly.
let handle: NodeJS.Timeout | undefined;
const timer: TimerSeam = {
  setTimer: (fn, ms) => (handle = setTimeout(fn, ms)),
  clearTimer: () => {
    if (handle !== undefined) clearTimeout(handle);
  },
};
const stop = runSpinner(frame, { timer, intervalMs: 80 });
// When the work finishes:
stop();