Function asyncio::wrap
[−]
[src]
pub fn wrap<T, F, R, E>(handler: F, data: &Arc<T>) -> ArcHandler<T, F, R, E>
Provides a Arc
handler to asynchronous operation.
The ArcHandler has trait the Handler
, that type of Handler::Output
is ()
.
Examples
use std::io; use std::sync::{Arc, Mutex}; use asyncio::{IoContext, wrap}; use asyncio::ip::{IpProtocol, Tcp, TcpSocket, TcpEndpoint, TcpListener}; fn on_accept(soc: Arc<Mutex<TcpListener>>, res: io::Result<(TcpSocket, TcpEndpoint)>) { if let Ok((acc, ep)) = res { println!("accepted {}", ep) } } let ctx = &IoContext::new().unwrap(); let soc = Arc::new(Mutex::new(TcpListener::new(ctx, Tcp::v4()).unwrap())); soc.lock().unwrap().async_accept(wrap(on_accept, &soc));