Cleanup blocking_iter return type

This commit is contained in:
Austen Adler 2021-05-14 21:33:44 -04:00
parent fd6cdf4d7d
commit 7a7a45ef4e

View File

@ -1,6 +1,5 @@
use std::iter;
use std::sync::mpsc;
use std::sync::mpsc::TryIter;
use std::thread;
use std::time::{Duration, Instant};
@ -45,20 +44,15 @@ impl Events {
})
};
Events {
tx: tx,
rx: rx,
tx,
rx,
tick_handle,
}
}
/// Returns a chain of the next element (blocking) and a TryIter of everything after it.
/// Useful for reading a single Iterator of all elements once after blocking, so there are not too many UI redraws.
pub fn blocking_iter(
&self,
) -> Result<iter::Chain<iter::Once<Event<KeyEvent>>, TryIter<Event<KeyEvent>>>, mpsc::RecvError>
{
Ok(iter::once(self.rx.recv()?)
.chain(self.rx.try_iter())
.into_iter())
pub fn blocking_iter(&self) -> Result<impl Iterator<Item = Event<KeyEvent>> + '_, mpsc::RecvError> {
Ok(iter::once(self.rx.recv()?).chain(self.rx.try_iter()))
}
}