handle

Function handle 

Source
pub fn handle() -> Handle
Expand description

Returns current loop handle

This only works if running inside the run() function of the main loop

ยงPanics

This function panics if there is no currently running loop (i.e. this function is not running from the inside of run().

Examples found in repository?
examples/multi-threaded.rs (line 24)
14fn main() {
15    let addr = env::args().nth(1).unwrap_or("127.0.0.1:7777".to_string());
16    let addr = addr.parse::<SocketAddr>().expect("parse address");
17
18    let socket = StdListener::bind(addr).expect("bind socket");
19    let mut threads = Vec::new();
20    for thread_no in 0..10 {
21        let lst = socket.try_clone().expect("cloning bind socket");
22        threads.push(thread::spawn(move || {
23            run(|| {
24                TcpListener::from_listener(lst, &addr, &handle())
25                .expect("listener created")
26                .incoming()
27                .for_each(|(_sock, addr)| {
28                    println!("Accepted {} in thread {}", addr, thread_no);
29                    Ok(())
30                })
31            })
32        }))
33    }
34    for t in threads {
35        t.join().expect("thread never joins").expect("accept never fails");
36    }
37}