For the latest stable version, please use Emilua API 0.10!

time.system_timer

local timer = require('time').system_timer
local t = timer.new()

A timer for the system_clock. As in Boost.Asio:

A waitable timer is always in one of two states: "expired" or "not expired". If the wait() or async_wait() function is called on an expired timer, the wait operation will complete immediately.

Changing an active waitable timer’s expiry time

Changing the expiry time of a timer while there are pending asynchronous waits causes those wait operations to be cancelled.

Functions

new() → system_timer

local t = system_timer.new()

Constructor. Returns a new system_timer object.

expires_at(self, tp: time.system_clock.time_point) → integer

Set the timer’s expiry time as an absolute time. Any pending asynchronous wait operations will be cancelled. The handler for each cancelled operation will be invoked with the boost::asio::error::operation_aborted error code.

Return Value

The number of asynchronous operations that were cancelled.

wait(self)

Initiate a wait operation on the timer and blocks current fiber until one of the events occur:

  • The timer has expired.

  • The timer was cancelled, in which case it raises boost::asio::error::operation_aborted.

cancel(self) → integer

Cancel any operations that are waiting on the timer. Returns the number of asynchronous operations that were cancelled.

Properties

expiry: time.system_clock.time_point

The timer’s expiry time as an absolute time.

Whether the timer has expired or not does not affect this value.