Skip to content

API Timers

Alexandre 'kidev' Poumaroux edited this page Oct 21, 2026 · 4 revisions

Timers

Import from proleak import timers

Timers driven by the game's frame loop. All callbacks run on the main thread.

Classes

Class
Timer Handle returned by every, after and on_frame.

Functions

Returns Function
Timer | Callable every(seconds: float, fn: Callable[[], None] | None = None) Calls fn every seconds.
Timer | Callable after(seconds: float, fn: Callable[[], None] | None = None) Calls fn once, seconds from now.
Timer on_frame(fn: Callable[[], None]) Call fn once per frame.

Function documentation

every

every(seconds: float, fn: Callable[[], None] | None = None) -> Timer | Callable

Calls fn every seconds.

Called with fn, it returns the Timer. Used as a decorator (@timers.every(5)), it starts the timer and leaves the function as it is.

after

after(seconds: float, fn: Callable[[], None] | None = None) -> Timer | Callable

Calls fn once, seconds from now.

Called with fn, it returns the Timer; used as a decorator, it starts the timer and leaves the function as it is.

on_frame

on_frame(fn: Callable[[], None]) -> Timer

Call fn once per frame. Keep it short: it shares the frame with the game.

Timer class

Handle returned by every, after and on_frame.

Type Property
str owner The id of the plugin that started it.
Callable[[], None] fn The function it calls.
float | None interval Seconds between calls; None for a timer that calls once or every frame.
bool cancelled True once it was cancelled or, for a timer that calls once, once it ran.
Returns Method
None cancel() Stop the timer.

Property documentation

owner

owner: str

The id of the plugin that started it.

fn

fn: Callable[[], None]

The function it calls.

interval

interval: float | None

Seconds between calls; None for a timer that calls once or every frame.

cancelled

cancelled: bool

True once it was cancelled or, for a timer that calls once, once it ran.

Method documentation

cancel

cancel() -> None

Stop the timer. Safe to call twice.


Previous: Sounds | Next: User interface

Clone this wiki locally