| f | import asyncio | f | import asyncio |
| | | |
| class Portal(asyncio.Barrier): | | class Portal(asyncio.Barrier): |
| | | |
| n | def __init__(self, parties): | n | def __init__(self, count): |
| super().__init__(parties) | | super().__init__(count) |
| self.topic = None | | self.topic = None |
| n | self._proposed_topic = None | n | self._tmp = None |
| self._out_barrier = asyncio.Barrier(parties) | | self._sync = asyncio.Barrier(count) |
| | | |
| n | async def wait(self, topic=None): | n | async def wait(self, t=None): |
| if topic is not None: | | if t is not None: |
| self._proposed_topic = topic | | self._tmp = t |
| idx = await super().wait() | | pos = await super().wait() |
| if idx == 0: | | if pos == 0: |
| self.topic = self._proposed_topic | | self.topic = self._tmp |
| await self._out_barrier.wait() | | await self._sync.wait() |
| return idx | | return pos |
| | | |
| async def reset(self): | | async def reset(self): |
| self.topic = None | | self.topic = None |
| n | self._proposed_topic = None | n | self._tmp = None |
| await super().reset() | | await super().reset() |
| t | await self._out_barrier.reset() | t | await self._sync.reset() |