Vital.sandbox
Thread

thread:create_heartbeat

Shared

Creates a new heartbeat context


Syntax

local ctx = thread:create_heartbeat(condition, exec, interval)

Parameters

TypeNameDescription
functionconditionConditional function - heartbeat continues while true, terminates when false
functionexecCallback function - executed upon heartbeat termination
intintervalExecution interval in milliseconds

Returns

TypeNameDescription
thread / boolctxReturns thread instance on successful execution, or false on failure

Examples

--Create a heartbeat that increments counter every second until it reaches 5
local counter = 0

local self = thread:create_heartbeat(
    function()
        return counter < 5
    end,

    function()
        counter = counter + 1
        engine.print("Heartbeat terminated:", counter)
    end, 1000
)

On this page