Closed Thomasdezeeuw closed 5 years ago
After some more consideration I've decided against this. It's fairly easy to create a wrapper around, for example, crossbeam's channel or any another thread-safe data structure. For example:
use crossbeam_channel::Receiver;
struct Events {
/// Receiving side of the channel for `Event`s.
receiver: Receiver<Event>,
}
impl<ES, E> event::Source<ES, E> for Events
where ES: event::Sink,
{
fn next_event_available(&self) -> Option<Duration> {
if !self.receiver.is_empty() {
Some(Duration::from_millis(0))
} else {
None
}
}
fn poll(&mut self, event_sink: &mut ES) -> Result<(), E> {
event_sink.extend(self.receiver.try_iter());
Ok(())
}
}
Also a good test of the flexibility and usability of the
event::Source
trait.