aiomas.clocks — aiomas 0.2.0 documentation

# `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 the `asyncio` 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`

  Interface for clocks.

  Clocks must at least implement `time()` and `utcnow()`.

  `time`()

    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`()

    Return an `arrow.arrow.Arrow` date with the current time in UTC.

  `sleep`(dt, result=None)

    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)

    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)

    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)

    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.` `AsyncioClock`

  `asyncio` based real-time clock.

class `aiomas.clocks.` `ExternalClock`(utc_start, init_time=0)

  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 that `arrow.factory.ArrowFactory.get()` can parse.