def listen_for_events(self, timeout=30000):
        response = self.api.event_stream(self.end, timeout)
        self.end = response["end"]

        for chunk in response["chunk"]:
            for listener in self.listeners:
                listener(chunk)
            if "room_id" in chunk:
                if chunk["room_id"] not in self.rooms:
                    self._mkroom(chunk["room_id"])
                self.rooms[chunk["room_id"]].events.append(chunk)
                for listener in self.rooms[chunk["room_id"]].listeners:
                    listener(chunk)
dataset/ETHPy150Open matrix-org/matrix-python-sdk/matrix_client/client.py/MatrixClient.listen_for_events/original