t | import asyncio | t | import asyncio |
| | | |
| class Seq: | | class Seq: |
| _next_to_run = 0 | | _next_to_run = 0 |
| _semaphores = [] | | _semaphores = [] |
| | | |
| def __init__(self, ident): | | def __init__(self, ident): |
| self.name = ident | | self.name = ident |
| sem = asyncio.Semaphore(0 if len(Seq._semaphores) else 1) | | sem = asyncio.Semaphore(0 if len(Seq._semaphores) else 1) |
| Seq._semaphores.append(sem) | | Seq._semaphores.append(sem) |
| self.index = len(Seq._semaphores) - 1 | | self.index = len(Seq._semaphores) - 1 |
| | | |
| async def run(self): | | async def run(self): |
| await Seq._semaphores[self.index].acquire() | | await Seq._semaphores[self.index].acquire() |
| print(self.name) | | print(self.name) |
| if self.index + 1 < len(Seq._semaphores): | | if self.index + 1 < len(Seq._semaphores): |
| Seq._semaphores[self.index + 1].release() | | Seq._semaphores[self.index + 1].release() |
| return self.name | | return self.name |