fn process_events(&mut self, tx_incoming: Sender<IncomingMessage>) {
        println!("CliAdapter: process_events");

        let (tx_outgoing, rx_outgoing) = channel();
        let name = self.get_name().to_owned();

        // Read from stdin and send messages to the main loop
        thread::Builder::new().name("Chatbot CLI Reader".to_owned()).spawn(move || {
            loop {
                let mut line = String::new();
                match io::stdin().read_line(&mut line) {
                    Ok(len) => {
                        if len == 0 {
                            break;
                        }
                        let msg = IncomingMessage::new(name.to_owned(), None, None, None,
                            line[..(len-1)].to_owned(),
                            tx_outgoing.to_owned());
                        tx_incoming.send(msg).unwrap();
                    },
                    Err(e) => {
                        println!("{:?}", e);
                        break;
                    }
                };
            }

            println!("CliAdapter: shutting down");
        }).ok().expect("failed to create stdio reader");

        // process messages from the main loop
        thread::Builder::new().name("Chatbot CLI".to_owned()).spawn(move || {
            loop {
                // TODO don't blindly unwrap
                match rx_outgoing.recv().unwrap() {
                    AdapterMsg::Outgoing(msg) => {
                        io::stdout().write(msg.as_bytes()).unwrap();
                        io::stdout().write(b"\n").unwrap();
                        io::stdout().flush().unwrap();
                    },
                    _ => break
                }
            }
        }).ok().expect("failed to create stdio <-> chatbot proxy");

    }
/// The CliAdapter uses two threads to
///
/// 1.  receive input from stdin and
/// 2.  listen for messages coming from the main thread. This implementation
///     may be horribly inefficient.
The CliAdapter uses two threads to
1.  receive input from stdin and
2.  listen for messages coming from the main thread. This implementation
may be horribly inefficient.
The CliAdapter uses two threads to 1 . receive input from stdin and 2 . listen for messages coming from the main thread . This implementation may be horribly inefficient .
fn process_events(&mut self, tx_incoming: Sender<IncomingMessage>) {
        println!("CliAdapter: process_events");
        let (tx_outgoing, rx_outgoing) = channel();
        let name = self.get_name().to_owned();
        // Read from stdin and send messages to the main loop
        thread::Builder::new().name("Chatbot CLI Reader".to_owned()).spawn(move || {
            loop {
                let mut line = String::new();
                match io::stdin().read_line(&mut line) {
                    Ok(len) => {
                        if len == 0 {
                            break;
                        }
                        let msg = IncomingMessage::new(name.to_owned(), None, None, None,
                            line[..(len-1)].to_owned(),
                            tx_outgoing.to_owned());
                        tx_incoming.send(msg).unwrap();
                    },
                    Err(e) => {
                        println!("{:?}", e);
                        break;
                    }
                };
            }
            println!("CliAdapter: shutting down");
        }).ok().expect("failed to create stdio reader");
        // process messages from the main loop
        thread::Builder::new().name("Chatbot CLI".to_owned()).spawn(move || {
            loop {
                // TODO don't blindly unwrap
                match rx_outgoing.recv().unwrap() {
                    AdapterMsg::Outgoing(msg) => {
                        io::stdout().write(msg.as_bytes()).unwrap();
                        io::stdout().write(b"\n").unwrap();
                        io::stdout().flush().unwrap();
                    },
                    _ => break
                }
            }
        }).ok().expect("failed to create stdio <-> chatbot proxy");
    }
fn process_events ( & mut self , tx_incoming : Sender < IncomingMessage > ) { println ! ( " " ) ; let ( tx_outgoing , rx_outgoing ) = channel ( ) ; let name = self . get_name ( ) . to_owned ( ) ; // Read from stdin and send messages to the main loop thread :: Builder :: new ( ) . name ( " " . to_owned ( ) ) . spawn ( move | | { loop { let mut line = String :: new ( ) ; match io :: stdin ( ) . read_line ( & mut line ) { Ok ( len ) => { if len == 0 { break ; } let msg = IncomingMessage :: new ( name . to_owned ( ) , None , None , None , line [ .. ( len - 1 ) ] . to_owned ( ) , tx_outgoing . to_owned ( ) ) ; tx_incoming . send ( msg ) . unwrap ( ) ; } , Err ( e ) => { println ! ( " " e ) ; break ; } } ; } println ! ( " " ) ; } ) . ok ( ) . expect ( " " ) ; // process messages from the main loop thread :: Builder :: new ( ) . name ( " " . to_owned ( ) ) . spawn ( move | | { loop { // TODO don't blindly unwrap match rx_outgoing . recv ( ) . unwrap ( ) { AdapterMsg :: Outgoing ( msg ) => { io :: stdout ( ) . write ( msg . as_bytes ( ) ) . unwrap ( ) ; io :: stdout ( ) . write ( b" \n " ) . unwrap ( ) ; io :: stdout ( ) . flush ( ) . unwrap ( ) ; } , _ => break } } } ) . ok ( ) . expect ( " " ) ; }
The CliAdapter uses two threads to
1.  receive input from stdin and
2.  listen for messages coming from the main thread.
The CliAdapter uses two threads to 1 . receive input from stdin and 2 . listen for messages coming from the main thread .
&mut self
tx_incoming
Sender<IncomingMessage>
&mut self
tx_incoming
Sender<IncomingMessage>