Cleanup blocking_iter return type
This commit is contained in:
parent
fd6cdf4d7d
commit
7a7a45ef4e
14
src/event.rs
14
src/event.rs
@ -1,6 +1,5 @@
|
|||||||
use std::iter;
|
use std::iter;
|
||||||
use std::sync::mpsc;
|
use std::sync::mpsc;
|
||||||
use std::sync::mpsc::TryIter;
|
|
||||||
|
|
||||||
use std::thread;
|
use std::thread;
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
@ -45,20 +44,15 @@ impl Events {
|
|||||||
})
|
})
|
||||||
};
|
};
|
||||||
Events {
|
Events {
|
||||||
tx: tx,
|
tx,
|
||||||
rx: rx,
|
rx,
|
||||||
tick_handle,
|
tick_handle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns a chain of the next element (blocking) and a TryIter of everything after it.
|
/// 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.
|
/// Useful for reading a single Iterator of all elements once after blocking, so there are not too many UI redraws.
|
||||||
pub fn blocking_iter(
|
pub fn blocking_iter(&self) -> Result<impl Iterator<Item = Event<KeyEvent>> + '_, mpsc::RecvError> {
|
||||||
&self,
|
Ok(iter::once(self.rx.recv()?).chain(self.rx.try_iter()))
|
||||||
) -> 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())
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user