diff --git a/examples/multithreaded.rs b/examples/multithreaded.rs new file mode 100644 index 0000000..38f4bc2 --- /dev/null +++ b/examples/multithreaded.rs @@ -0,0 +1,36 @@ +#![feature(if_let)] +#![feature(slicing_syntax)] +extern crate irc; + +use std::collections::HashMap; +use std::sync::Arc; +use irc::data::config::Config; +use irc::server::{IrcServer, Server}; +use irc::server::utils::Wrapper; + +fn main() { + let config = Config { + owners: vec!("awe".into_string()), + nickname: "pickles".into_string(), + username: "pickles".into_string(), + realname: "pickles".into_string(), + password: "".into_string(), + server: "irc.fyrechat.net".into_string(), + port: 6667, + use_ssl: false, + channels: vec!("#vana".into_string()), + options: HashMap::new(), + }; + let irc_server = Arc::new(IrcServer::from_config(config).unwrap()); + // The wrapper provides us with methods like send_privmsg(...) and identify(...) + let server = Wrapper::new(&*irc_server); + server.identify().unwrap(); + let server = irc_server.clone(); + // We won't use a wrapper here because we don't need the added functionality. + spawn(proc() { + for msg in server.iter() { + print!("{}", msg.into_string()); + } + }); +} + diff --git a/examples/simple.rs b/examples/simple.rs index e30beb9..d7efc75 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -21,7 +21,8 @@ fn main() { options: HashMap::new(), }; let irc_server = IrcServer::from_config(config).unwrap(); - let server = Wrapper::new(&irc_server); + // The wrapper provides us with methods like send_privmsg(...) and identify(...) + let server = Wrapper::new(&irc_server); server.identify().unwrap(); for message in server.iter() { print!("{}", message.into_string()); diff --git a/examples/simple_ssl.rs b/examples/simple_ssl.rs index 53a66eb..923f350 100644 --- a/examples/simple_ssl.rs +++ b/examples/simple_ssl.rs @@ -21,6 +21,7 @@ fn main() { options: HashMap::new(), }; let irc_server = IrcServer::from_config(config).unwrap(); + // The wrapper provides us with methods like send_privmsg(...) and identify(...) let server = Wrapper::new(&irc_server); server.identify().unwrap(); for message in server.iter() {