summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2014-09-06 17:51:16 -0400
committerJesse Luehrs <doy@tozt.net>2014-09-06 17:51:16 -0400
commit2d401b7685e6f142c5945075ba2d79abfa781f49 (patch)
tree1f836f9df5321986b4bd33196cf765a2d5ac6aa0
parentdf1b563b1f14443d685f3b035f749090b764d63d (diff)
downloadrust-irc-2d401b7685e6f142c5945075ba2d79abfa781f49.tar.gz
rust-irc-2d401b7685e6f142c5945075ba2d79abfa781f49.zip
add a basic runloop
-rw-r--r--examples/client.rs8
-rw-r--r--src/client.rs12
2 files changed, 15 insertions, 5 deletions
diff --git a/examples/client.rs b/examples/client.rs
index 98900ef..f1f2479 100644
--- a/examples/client.rs
+++ b/examples/client.rs
@@ -2,9 +2,7 @@ extern crate irc;
fn main () {
let mut client = irc::ClientBuilder::new("doytest", "chat.freenode.net").connect();
-
- loop {
- let res = client.read();
- println!("{}", res);
- }
+ client.run_loop_with(|m| {
+ println!("{}", m);
+ });
}
diff --git a/src/client.rs b/src/client.rs
index 2824df2..3beda7d 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -133,4 +133,16 @@ impl Client {
None => None,
}
}
+
+ // XXX eventually, we'll want to set up callbacks for specific events
+ // beforehand, and just have a `run_loop` method that loops and calls the
+ // preset callbacks as necessary. unfortunately, rust doesn't handle
+ // storing closures very well yet if they need to receive a borrowed
+ // pointer, and we would need to pass the client object into the callback
+ // in order to make this work
+ pub fn run_loop_with (&mut self, handler: |Message|) {
+ loop {
+ handler(self.read());
+ }
+ }
}