Updated examples with removal of deprecated code.
This commit is contained in:
parent
4fdf801fb3
commit
b3e3b8becd
3 changed files with 10 additions and 5 deletions
|
@ -3,6 +3,7 @@ extern crate irc;
|
|||
|
||||
use std::default::Default;
|
||||
use std::sync::Arc;
|
||||
use std::thread::Thread;
|
||||
use irc::data::{Command, Config};
|
||||
use irc::server::{IrcServer, Server};
|
||||
use irc::server::utils::Wrapper;
|
||||
|
@ -17,7 +18,7 @@ fn main() {
|
|||
let irc_server = Arc::new(IrcServer::from_config(config).unwrap());
|
||||
irc_server.conn().set_keepalive(Some(5)).unwrap();
|
||||
// The wrapper provides us with methods like send_privmsg(...) and identify(...)
|
||||
spawn(move || {
|
||||
let _ = Thread::spawn(move || {
|
||||
let server = Wrapper::new(&*irc_server);
|
||||
server.identify().unwrap();
|
||||
loop {
|
||||
|
@ -41,5 +42,5 @@ fn main() {
|
|||
irc_server.reconnect().unwrap();
|
||||
server.identify().unwrap();
|
||||
}
|
||||
});
|
||||
}).join();
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@ extern crate irc;
|
|||
|
||||
use std::default::Default;
|
||||
use std::sync::Arc;
|
||||
use std::thread::Thread;
|
||||
use irc::data::config::Config;
|
||||
use irc::server::{IrcServer, Server};
|
||||
use irc::server::utils::Wrapper;
|
||||
|
@ -20,9 +21,9 @@ fn main() {
|
|||
server.identify().unwrap();
|
||||
let server = irc_server.clone();
|
||||
// We won't use a wrapper here because we don't need the added functionality.
|
||||
spawn(move || {
|
||||
let _ = Thread::spawn(move || {
|
||||
for msg in server.iter() {
|
||||
print!("{}", msg.unwrap().into_string());
|
||||
}
|
||||
});
|
||||
}).join(); // You might not want to join here for actual multi-threading.
|
||||
}
|
||||
|
|
|
@ -4,6 +4,7 @@ extern crate irc;
|
|||
use std::default::Default;
|
||||
use std::io::timer::sleep;
|
||||
use std::sync::Arc;
|
||||
use std::thread::Thread;
|
||||
use std::time::duration::Duration;
|
||||
use irc::data::config::Config;
|
||||
use irc::server::{IrcServer, Server};
|
||||
|
@ -22,7 +23,9 @@ fn main() {
|
|||
let server = Wrapper::new(&*irc_server2);
|
||||
server.identify().unwrap();
|
||||
// Let's set up a loop that just prints the messages.
|
||||
spawn(move || { irc_server.iter().map(|m| print!("{}", m.unwrap().into_string())).count(); });
|
||||
Thread::spawn(move || {
|
||||
irc_server.iter().map(|m| print!("{}", m.unwrap().into_string())).count();
|
||||
}).detach();
|
||||
loop {
|
||||
server.send_privmsg("#vana", "TWEET TWEET").unwrap();
|
||||
sleep(Duration::seconds(10))
|
||||
|
|
Loading…
Reference in a new issue