Python: Add drain method to get all events within the dora queue
In order to reduce having too many filled queues., node.drain() enable to get all event from all input as a vec/list.
In order to make this fast and manageable the order of draining is going to be first ordered by topic and then by time of arrival
I'm not sure if this is the best approach to empty the queues. How about we instead add a try_recv method that doesn't block or awaits anything? So it behaves like recv, but returns None instead of waiting for the next event if there is nothing in the queue.
Such a function would allow node authors to empty the queue themselves by just calling try_recv in a loop. For convenience, we could also provide a drain method based on it:
fn drain(&mut self) -> Vec<Event> {
let mut events = Vec::new();
while let Some(event) = self.try_recv() {
events.push(event);
}
events
}
This pattern is common in the Rust ecosystem.
In order to make this fast and manageable the order of draining is going to be first ordered by topic and then by time of arrival
I'm not sure if I understand this part. How is a different drain order faster?
I just opened https://github.com/dora-rs/dora/pull/1185 to provied a simpler drain method based on try_recv.