Capy-Bearer Documentation

service_every

lib call

Capy

function service_every(signal : string, interval_ms : u64, props : as any = {}) bool

Description

service_every() is the interval timer of a service. The loop delivers SERVICE:<signal> with the props and re-arms the timer after that delivery returns. A slow handler stretches the interval instead of stacking ticks in the mailbox.

One timer exists per signal name. A second call replaces the interval and props. Zero cancels the timer. Timers belong to the worker. After a restart, SERVICE:START must set them again.

Parameters

signal : the handler name without the SERVICE: prefix

interval_ms : the time between deliveries, zero cancels the timer

props : the message delivered with every tick

Return Values

true inside a service worker

Errors

Outside a service worker the call traps, because only a service has a loop to own the timer.

Example

Capy

function SERVICE:START()
{
	service_every("REPORT", 60000, verbose: true)
}

function SERVICE:REPORT(props : any)
{
	if props.verbose
	{
		print("report tick\n")
	}
	service_every("REPORT", 0)
}

Save this unit and start it with service_start(unit). The first tick arrives after sixty seconds. The handler cancels further ticks. Signal names are case-sensitive. Pass REPORT, not SERVICE:REPORT.