Ticker
Timers and sequences that advance with the app tick.
Always available
No import needed. These names are in scope in every file.
Cancelled class
ts
class Cancelled extends ErrorThe error a pending await ticker.wait(...) rejects with when its ticker or handle is disposed.
ts
constructor(message: string = "Cancelled")TickerHandle class
ts
class TickerHandleOne entry on a ticker: what every/everyTicks return. Also the record for one-shots and waitUntil.
TickerHandle.name
ts
get name(): stringThe name given in opts.name, or "" .
TickerHandle.remaining
ts
get remaining(): intTicks until this entry next runs (waitUntil: -1; stopped: 0). Held value while paused.
TickerHandle.dispose
ts
dispose(): voidStops this entry. A pending await on it rejects with Cancelled.
Other members of TickerHandle
ts
owner: any
kind: int
label: string
interval: int
phase: int
due: int
heapIndex: int
seq: int
maxRuns: int
runs: int
callback: any
predicate: any
resolveFn: any
rejectFn: any
isDead: boolean
isSuspended: boolean
heldRemaining: int
immediatePending: boolean
get paused(): boolean
set paused(value: boolean)TickerInfo class
ts
class TickerInfoWhat Ticker.list() returns for each live entry.
ts
name: string
kind: string
interval: int
nextDue: int
runs: int
paused: booleanTicker class
ts
class TickerTicker.tick
ts
tick: intTicks this ticker has run. The first advance() (at timeScale 1) is tick 1.
Ticker.timeScale
ts
timeScale: floatScales how many ticks of work each advance() runs (0.5: every second call).
Ticker.paused
ts
paused: booleanA paused ticker's advance() runs nothing, and its counters hold.
new Ticker()
ts
constructor(tps: float = 0.0)tps is the tick rate seconds convert with. 0 (default) reads App.tps.
Ticker.size
ts
get size(): intThe number of live entries (handles not yet finished or disposed).
Ticker.every
ts
every(seconds: float, fn: any, opts: any = undefined): TickerHandleRuns fn every seconds (rounded to whole ticks, at least 1). See everyTicks for opts.
Ticker.everyTicks
ts
everyTicks(n: int, fn: any, opts: any = undefined): TickerHandleRuns fn every n ticks. opts: name (an existing name on this ticker is replaced), count (stop after that many runs), phase (tick offset within the period), spread: true (stagger same-interval entries across the period), immediate (also run on the next tick).
Ticker.wait
ts
wait(seconds: float, fn: any = undefined): Promise<void>Runs fn once after seconds; await ticker.wait(s) waits. Cancelled by dispose (the promise rejects Cancelled).
Ticker.waitTicks
ts
waitTicks(n: int, fn: any = undefined): Promise<void>Runs fn once after n ticks (at least 1); await ticker.waitTicks(n) waits.
Ticker.waitUntil
ts
waitUntil(predicate: any, fn: any = undefined): Promise<void>Runs fn once, on the first tick predicate() is true (checked every tick); await ticker.waitUntil(p) waits.
Ticker.advance
ts
advance(): voidRuns one tick of work, or none, one, or several of them when timeScale is not 1.
Ticker.fail
ts
fail(h: TickerHandle, e: any): voidA callback threw: report it once and drop its entry.
Ticker.list
ts
list(): Array<TickerInfo>The live entries (name, kind, interval, next due tick, run count), for debugging. Allocates; not for hot paths.
Ticker.dispose
ts
dispose(): voidCancels everything: pending awaits reject with Cancelled. The ticker runs nothing afterwards.
Other members of Ticker
ts
tpsValue: float
accumulator: float
buckets: Array<TickerBucket>
bucketByInterval: Map<int, TickerBucket>
spreadNext: Map<int, int>
named: Map<string, TickerHandle>
heap: Array<TickerHandle>
untils: Array<TickerHandle>
immediates: Array<TickerHandle>
held: Array<TickerHandle>
dirty: boolean
sequence: int
live: int
disposed: boolean
get tps(): float
ticksFor(seconds: float): int
settleLater(handle: TickerHandle): Promise<void>
claimName(handle: TickerHandle): void
runTick(): void
run(h: TickerHandle): void
remove(h: TickerHandle, cancel: boolean): void
unhold(h: TickerHandle): void
compact(): void
addToWheel(h: TickerHandle): void
remainingOf(h: TickerHandle): int
suspend(h: TickerHandle): void
resume(h: TickerHandle): void
heapLess(a: TickerHandle, b: TickerHandle): boolean
heapPush(h: TickerHandle): void
heapPop(): TickerHandle
heapRemoveAt(index: int): void
siftUp(start: int): void
siftDown(start: int): void
swap(a: int, b: int): voidGenerated from lang/ticker/index.tks in the ThicketScript repository.