Wait for an event of the given type and return it. This is an async context manager, so you should open it inside an async with block. The block will not exit until the indicated event is received.
(self, event_type: type[T], buffer_size=10)
| 244 | |
| 245 | @asynccontextmanager |
| 246 | async def wait_for(self, event_type: type[T], buffer_size=10) -> AsyncGenerator[CmEventProxy, None]: |
| 247 | """Wait for an event of the given type and return it. |
| 248 | |
| 249 | This is an async context manager, so you should open it inside |
| 250 | an async with block. The block will not exit until the indicated |
| 251 | event is received. |
| 252 | """ |
| 253 | sender: trio.MemorySendChannel |
| 254 | receiver: trio.MemoryReceiveChannel |
| 255 | sender, receiver = trio.open_memory_channel(buffer_size) |
| 256 | self.channels[event_type].add(sender) |
| 257 | proxy = CmEventProxy() |
| 258 | yield proxy |
| 259 | async with receiver: |
| 260 | event = await receiver.receive() |
| 261 | proxy.value = event |
| 262 | |
| 263 | def _handle_data(self, data): |
| 264 | """Handle incoming WebSocket data. |
no test coverage detected