timer — Create a timer handle object for scheduled callbacks.
timer creates a handle object with callback, timing, execution, visibility, and user-data properties. Use start, startat, stop, wait, and delete to control its lifecycle, and use timerfind or timerfindall to retrieve valid timers.
Syntax
t = timer
t = timer(Name, Value, ...)Inputs
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
Name,Value | Any | Variadic | — | Timer properties such as TimerFcn, StartDelay, Period, ExecutionMode, Name, Tag, and UserData. |
Returns
| Name | Type | Description |
|---|---|---|
t | Any | Timer handle object. |
Errors
| Identifier | When | Message |
|---|---|---|
RunMat:timer:InvalidInput | A timer argument, property, or callback value has an unsupported type. | timer: invalid input |
RunMat:timer:InvalidProperty | A timer property name is unknown, read-only, or has an invalid value. | timer: invalid property |
RunMat:timer:InvalidHandle | A lifecycle method receives a non-timer or invalid timer handle. | timer: invalid timer handle |
RunMat:timer:CallbackFailed | A timer callback fails. | timer: callback failed |
RunMat:timer:GcFailure | A timer object cannot be allocated, rooted, read, or mutated. | timer: object storage failed |
How timer works
t = timercreates a valid timer handle with defaults:ExecutionMode='singleShot',Period=1,StartDelay=0,TasksToExecute=1,BusyMode='drop',ObjectVisibility='on',Running='off',TasksExecuted=0,Type='timer', and a generatedName.t = timer(Name, Value, ...)accepts common callback, timing, labeling, and user-data properties:TimerFcn,StartFcn,StopFcn,ErrorFcn,Period,StartDelay,TasksToExecute,BusyMode,ExecutionMode,Name,Tag,ObjectVisibility, andUserData.- Callback properties accept strings, character rows, function handles, closures, or callback cell arrays. Function-handle, closure, and callback-cell callbacks execute directly; non-empty text callbacks are not yet executable.
start(t)validatesTimerFcn, marksRunning='on', executesStartFcn, executesTimerFcnonce forsingleShotorTasksToExecutetimes for fixed execution modes, updatesTasksExecuted,InstantPeriod, andAveragePeriod, then executesStopFcnand marksRunning='off'.startat(t, delaySeconds)is supported for numeric positive relative delays. MATLAB date/time and date-string start times are not yet implemented.stop(t)marks the timer stopped and runsStopFcnif the timer was running.wait(t)returns after the timer is stopped.delete(t)invalidates the handle, removes it from timer discovery, and releases its GC root.- Timer callbacks currently run synchronously on the current VM path. Long delays therefore block the caller on native hosts; background event-queue scheduling is not yet available.
TasksToExecuteretains a native integer scalar exactly.PeriodandStartDelayare stored as seconds and reject integer values that cannot cross the binary64 seconds boundary exactly.UserDatapreserves native integer class, shape, and payload without numeric conversion.- Multiple timers are currently returned as a cell row.
Does RunMat run timer on the GPU?
timer is a control-flow and callback object. It gathers no tensors, allocates no GPU buffers, and does not participate in fusion.
Examples
Create and start a one-shot timer
t = timer('TimerFcn', @(src, evt)disp("tick"));
start(t)Find a timer by tag
t = timer('Tag', 'batch', 'TimerFcn', @tick);
found = timerfind('Tag', 'batch')Using timer with coding agents
Open a RunMat example with live inputs, then ask the agent to explain how timer changes the result.
Run a small timer example, explain the result, then change one input and compare the output.
FAQ
Does RunMat run timers in the background?⌄
No. Timer callbacks run synchronously when start drives the timer. Background scheduling requires an event queue that is not yet available.
Can timer callbacks use GPU arrays?⌄
Yes, when the callback body calls GPU-capable builtins. The timer object itself is host-side control flow and has no GPU kernel.
Related Timing functions
Open-source implementation
Unlike proprietary runtimes, every RunMat function is open-source. Read exactly how timer is executed, line by line, in Rust.
- View the source for timer in Rust on GitHub
- Learn how the RunMat runtime works
- Found a bug? Open an issue with a minimal reproduction.
About RunMat
RunMat is an open-source runtime that executes MATLAB-syntax code blazing on any GPU. It is licensed under the Apache 2.0 license.
- RunMat automatically optimizes your math for GPU execution on Apple, Nvidia, and AMD hardware. No code changes needed. Simulations that took hours now take minutes.
- Start running code in seconds. RunMat runs in the browser, on the desktop, or from the CLI. No license server, no IT ticket.