aiomas.clocks
¶
Clocks to be used with aiomas.agent.Container
.
All clocks should subclass BaseClock
. Currently available clock types
are:
AsyncioClock
: a real-time clock synchronized with theasyncio
event loop.ExternalClock
: a clock that can be set by external tasks / processes in order to synchronize it with external systems or simulators.
-
class
aiomas.clocks.
BaseClock
[source]¶ Interface for clocks.
Clocks must at least implement
time()
andutcnow()
.-
time
()[source]¶ Return the value (in seconds) of a monotonic clock.
The return value of consecutive calls is guaranteed to be greater or equal then the results of previous calls.
The initial value may not be defined. Don’t depend on it.
-
utcnow
()[source]¶ Return an
arrow.arrow.Arrow
date with the current time in UTC.
-
sleep
(dt, result=None)[source]¶ Sleep for a period dt in seconds. Return an
asyncio.Future
.If result is provided, it will be passed back to the caller when the coroutine has finished.
-
sleep_until
(t, result=None)[source]¶ Sleep until the time t. Return an
asyncio.Future
.t may either be a number in seconds or an
arrow.arrow.Arrow
date.If result is provided, it will be passed back to the caller when the coroutine has finished.
-
call_in
(dt, func, *args)[source]¶ Schedule the execution of
func(*args)
in dt seconds and return immediately.Return an opaque handle which lets you cancel the scheduled call via its
cancel()
method.
-
call_at
(t, func, *args)[source]¶ Schedule the execution of
func(*args)
at t and return immediately.t may either be a number in seconds or an
arrow.arrow.Arrow
date.Return an opaque handle which lets you cancel the scheduled call via its
cancel()
method.
-
-
class
aiomas.clocks.
ExternalClock
(utc_start, init_time=0)[source]¶ A clock that can be set by external process in order to synchronize it with other systems.
The initial UTC date utc_start may either be an
arrow.arrow.Arrow
instance or something thatarrow.factory.ArrowFactory.get()
can parse.
-
class
aiomas.clocks.
TimerHandle
(future, callback)[source]¶ This class lets you cancel calls scheduled by
ExternalClock
.