Loading homepage
Input: const calls = []; const cancel = cancellableInterval(() => calls.push("tick"), 100); // Advance a controlled clock to 250 ms, then cancel(). Output: calls is ["tick", "tick"] from the scheduled 100 ms and 200 ms ticks. Later ticks are cancelled.
Input: const cancel = cancellableInterval((name, count) => console.log(name, count), 100, "Ada", 2); Output: Each invocation receives "Ada" and 2; cancel is a function.
Input: const cancel = cancellableInterval(() => console.log("tick"), 100); cancel(); cancel(); Output: No callback is invoked if cancelled before the first tick. Both cancellation calls are safe.
cancellableInterval(callback, delay, ...args) returns () => void. The callback receives only the supplied extra arguments. TypeScript infers a tuple of callback argument types so supplied arguments must match. Invoke cancel() to stop later ticks; invoking it again is harmless.