async def stream(self,<EOL>event_type: Type[TStreamEvent],<EOL>num_events: Optional[int] = None) -> AsyncGenerator[TStreamEvent, None]:
queue: asyncio.Queue = asyncio.Queue()<EOL>if event_type not in self._queues:<EOL><INDENT>self._queues[event_type] = []<EOL><DEDENT>self._queues[event_type].append(queue)<EOL>i = None if num_events is None else <NUM_LIT:0><EOL>while True:<EOL><INDENT>try:<EOL><INDENT>yield await queue.get()<EOL><DEDENT>except GeneratorExit:<EOL><INDENT>self._queues[event_type].remove(queue)<EOL>break<EOL><DEDENT>except asyncio.CancelledError:<EOL><INDENT>self._queues[event_type].remove(queue)<EOL>break<EOL><DEDENT>else:<EOL><INDENT>if i is None:<EOL><INDENT>continue<EOL><DEDENT>i += <NUM_LIT:1><EOL>if i >= cast(int, num_events):<EOL><INDENT>self._queues[event_type].remove(queue)<EOL>break<EOL><DEDENT><DEDENT><DEDENT>
Stream all events that match the specified event type. This returns an
``AsyncIterable[BaseEvent]`` which can be consumed through an ``async for`` loop.
An optional ``num_events`` parameter can be passed to stop streaming after a maximum amount
of events was received.