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