2020-06-17 15:58:00 +02:00
|
|
|
from giambio import AsyncScheduler, sleep, TaskManager
|
2020-06-16 18:56:11 +02:00
|
|
|
|
|
|
|
|
|
|
|
async def countdown(n: int):
|
|
|
|
while n > 0:
|
|
|
|
print(f"Down {n}")
|
|
|
|
n -= 1
|
|
|
|
await sleep(1)
|
2020-06-17 15:58:00 +02:00
|
|
|
if n == 5:
|
|
|
|
raise ValueError('lul')
|
2020-06-16 18:56:11 +02:00
|
|
|
print("Countdown over")
|
|
|
|
|
|
|
|
|
|
|
|
async def countup(stop, step: int or float = 1):
|
|
|
|
x = 0
|
|
|
|
while x < stop:
|
|
|
|
print(f"Up {x}")
|
|
|
|
x += 1
|
|
|
|
await sleep(step)
|
|
|
|
print("Countup over")
|
|
|
|
|
|
|
|
|
|
|
|
async def main():
|
2020-06-17 15:58:00 +02:00
|
|
|
async with TaskManager(scheduler) as manager:
|
|
|
|
manager.spawn(countdown(10))
|
|
|
|
manager.spawn(countup(5, 2))
|
|
|
|
print("Counters started, awaiting completion")
|
2020-06-16 18:56:11 +02:00
|
|
|
print("Task execution complete")
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
scheduler = AsyncScheduler()
|
|
|
|
scheduler.start(main())
|
|
|
|
|