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