| t | import asyncio | t | import asyncio |
| | | |
| class Loop: | | class Loop: |
| _funcs = [] | | _funcs = [] |
| _stop = False | | _stop = False |
| _count = 0 | | _count = 0 |
| | | |
| def __init__(self): | | def __init__(self): |
| self.idx = Loop._count | | self.idx = Loop._count |
| Loop._count += 1 | | Loop._count += 1 |
| Loop._funcs.append(None) | | Loop._funcs.append(None) |
| | | |
| def __call__(self, func): | | def __call__(self, func): |
| Loop._funcs[self.idx] = func | | Loop._funcs[self.idx] = func |
| | | |
| async def wrapper(*args, **kwargs): | | async def wrapper(*args, **kwargs): |
| if Loop._stop: | | if Loop._stop: |
| return None | | return None |
| my_counter = 0 | | my_counter = 0 |
| while True: | | while True: |
| if Loop._stop: | | if Loop._stop: |
| return None | | return None |
| result = await func(*args, **kwargs) | | result = await func(*args, **kwargs) |
| my_counter += 1 | | my_counter += 1 |
| if result is None: | | if result is None: |
| Loop._stop = True | | Loop._stop = True |
| return None | | return None |
| await asyncio.sleep(0) | | await asyncio.sleep(0) |
| return wrapper | | return wrapper |