Search docs
Search modules and symbols
Modules

Docs / API / Modules / timers

Timers

Platform

@s2script/sdk/timers

Tick-integrated async timing: delay, nextTick, nextFrame, threadSleep.

Import

import { delay } from "@s2script/sdk/timers";

Author-time types ship in the npm package; the engine injects the runtime at plugin load. Add @s2script/sdk to your plugin's dependencies.

API reference

Generated from the shipped type definitions.

fn
delay(ms: number): Promise<void>

Await a delay of ms milliseconds before continuing. Tick-integrated (resumes on a game frame).

import { delay } from "@s2script/sdk/timers";
// plugins/funcommands/src/plugin.ts:77 — sm_freeze auto-unfreeze after `secs`
delay(secs * 1000).then(() => { const q = Player.fromSlot(slot); if (q && q.pawn) q.pawn.moveType = WALK; });
fn
nextTick(): Promise<void>

Yield to the next microtick.

fn
nextFrame(): Promise<void>

Yield until the next game frame.

fn
threadSleep(ms: number): void

Block the current thread (fiber) for ms milliseconds. Only valid inside a threadSleep-capable fiber context.

interface
Timer

A live callback timer, returned by after and every. Ledgered against the creating plugin: unload kills it whether or not kill() was called, so a repeating timer can never outlive its plugin and fire into a dead context.

readonly alive: boolean
False once the timer has fired (one-shot), been killed, or had its plugin unloaded.
kill(): boolean
Cancel it. Idempotent — returns false if it was already dead. Safe to call from inside the callback.
fn
after(ms: number, fn: () => void): Timer

Run fn once after ms milliseconds (SourceMod CreateTimer without TIMER_REPEAT). Prefer delay when you can await; use this when you need something cancellable. A throwing callback is reported and contained — it never kills the frame or the timer system.

import { after } from "@s2script/sdk/timers";
const t = after(5000, () => console.log("5s later"));
t.kill();   // ...unless cancelled first
fn
every(ms: number, fn: () => void): Timer

Run fn every ms milliseconds until killed (SourceMod CreateTimer with TIMER_REPEAT). The next firing is scheduled *after* the callback returns, so a slow callback cannot pile up. ms must be greater than 0 — a zero-interval repeat would re-arm every drain and starve the frame, so it throws rather than degrading.

import { every } from "@s2script/sdk/timers";
const tick = every(1000, () => console.log("tick"));
// later: tick.kill();
Back to modules All packages

s2script — Source 2 plugin framework

GitHub