Added for_each_incoming helper to Server.

This commit is contained in:
Aaron Weiss 2017-06-21 22:07:53 -04:00
parent f0e49d403f
commit 8c9a1aca2c
No known key found for this signature in database
GPG key ID: 0237035D9BF03AE2
4 changed files with 23 additions and 12 deletions

View file

@ -33,6 +33,17 @@ pub trait Server {
/// Gets a stream of incoming messages from the Server.
fn stream(&self) -> ServerStream;
/// Blocks on the stream, running the given function on each incoming message as they arrive.
fn for_each_incoming<F>(&self, mut f: F) -> ()
where
F: FnMut(Message) -> (),
{
self.stream().for_each(|msg| {
f(msg);
Ok(())
}).wait().unwrap()
}
/// Gets a list of currently joined channels. This will be none if tracking is not supported
/// altogether (such as when the `nochanlists` feature is enabled).
fn list_channels(&self) -> Option<Vec<String>>;