Some checks failed
Deploy MkDocs / deploy (push) Has been cancelled
Makes commonly used classes, functions, and decorators from `disagreement.ext` and `disagreement.ui` submodules directly accessible under the `disagreement` namespace. This change simplifies import statements for users, leading to cleaner and more concise code. Documentation and examples have been updated to reflect these new, simplified import paths.
31 lines
619 B
Python
31 lines
619 B
Python
"""Example showing the tasks extension."""
|
|
|
|
import asyncio
|
|
import os
|
|
import sys
|
|
|
|
# Allow running from the examples folder without installing
|
|
if os.path.join(os.getcwd(), "examples") == os.path.dirname(os.path.abspath(__file__)):
|
|
sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), "..")))
|
|
|
|
from disagreement import loop
|
|
|
|
counter = 0
|
|
|
|
|
|
@loop(seconds=1.0)
|
|
async def ticker() -> None:
|
|
global counter
|
|
counter += 1
|
|
print(f"Tick {counter}")
|
|
|
|
|
|
async def main() -> None:
|
|
ticker.start()
|
|
await asyncio.sleep(5)
|
|
ticker.stop()
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|