For the latest stable version, please use Emilua API 0.10! |
time.steady_timer
local timer = require('time').steady_timer
local t = timer.new()
spawn(function() print('Hello') end)
t:expires_after(2) --< 2 seconds
t:wait()
print('World')
A monotonic timer (i.e. the time points of the underlying clock cannot decrease as physical time moves forward). As in Boost.Asio:
A waitable timer is always in one of two states: "expired" or "not expired". If the
wait()
orasync_wait()
function is called on an expired timer, the wait operation will complete immediately.Changing an active waitable timer’s expiry timeChanging the expiry time of a timer while there are pending asynchronous waits causes those wait operations to be cancelled.
Functions
expires_at(self, tp: time.steady_clock.time_point) → integer
Forward the call to the function with same name in Boost.Asio:
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 ValueThe number of asynchronous operations that were cancelled.
expires_after(self, secs: number) → integer
Forward the call to the function with same name in Boost.Asio:
Set the timer’s expiry time relative to now. 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 ValueThe number of asynchronous operations that were cancelled.
Expiry time is given in seconds.