@mocanvas/editor · class

Timers

declare class Timers

Per-editor timers.

Every setTimeout, setInterval and requestAnimationFrame scheduled through this manager is remembered and cancelled when the editor is disposed. Work scheduled by a tool, a side effect or a host integration therefore cannot outlive the editor it belongs to and fire against a torn-down store — the usual source of "cannot read properties of undefined" after unmount.

Handles are this manager's own; they are only meaningful to its clear* methods, never to the global ones.


Methods · 9

cancelAnimationFrame(handle: number | undefined): void

Cancel a pending animation frame. Unknown handles are ignored.

clearInterval(handle: number | undefined): void

Cancel a repeating interval. Unknown handles are ignored.

clearTimeout(handle: number | undefined): void

Cancel a pending timeout. Unknown handles are ignored.

constructor(getWindow?: () => Window | undefined)

@param getWindow - The realm to schedule in; see getOwnerWindow. When it yields nothing (node, SSR) the globals are used, and animation frames fall back to a ~60fps timeout.

dispose(): void

Cancel everything. Further scheduling is a no-op.

getPendingCount(): number

How much work is still scheduled. Useful in tests and leak checks.

requestAnimationFrame(fn: (time: number) => void): number

Run fn before the next paint of the editor's own window. Where there is no requestAnimationFrame (node) a 16ms timeout stands in, so scheduling code does not have to branch on the environment.

setInterval(fn: () => void, ms: number): number

Run fn every ms until cancelled or the editor is disposed.

setTimeout(fn: () => void, ms?: number): number

Run fn after ms. The handle is released once it fires.

mocanvas is built by Symbio. Free for non-commercial, non-profit and development use; commercial use needs an agreement. Not affiliated with or endorsed by tldraw.