aio
multimer.aio ¶
asyncio/uasyncio Timer for multimer.
Opt-in module — not wired into multimer.Timer. Use when the app runs under
asyncio/uasyncio. See docs/concepts/multimer.md for full documentation.
Quick start (helpers are optional)::
from multimer.aio import Timer, run_queued, run
async def main():
t = Timer()
t.init(mode=Timer.PERIODIC, period=33, callback=cb)
while True:
broker.poll()
display.show()
await run_queued() # or await asyncio.sleep(0)
run(main) # or asyncio.run(main())
run_queued and run are convenience wrappers only. Any await that
yields to the event loop is sufficient for timer callbacks to fire.
Classes¶
Timer ¶
Timer(id=-1, **kwargs)
asyncio/uasyncio software Timer.
Methods:¶
init ¶
init(*, mode, freq=-1, period=-1, callback=None)
Initialize the timer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mode
|
int
|
Timer mode (Timer.ONE_SHOT or Timer.PERIODIC). |
required |
freq
|
int
|
Timer frequency in Hz. Defaults to -1. |
-1
|
period
|
int
|
Timer period in milliseconds. Ignored if freq is specified. Defaults to -1. |
-1
|
callback
|
callable
|
Callable to execute upon timer expiration. Defaults to None. |
None
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If an invalid timer mode or interval is provided. |
Functions:¶
run_queued
async
¶
run_queued()
Yield to the event loop so asyncio timer tasks can run.
Optional helper — equivalent to await asyncio.sleep(0) (or sleep_ms(0)).
Not related to sync multimer.run_queued() from the top-level package.
run ¶
run(main)
Run an async main coroutine function under asyncio/uasyncio.
Optional helper — equivalent to asyncio.run(main()) when available.