Crates.io | cancellable-io |
lib.rs | cancellable-io |
version | 0.1.1 |
source | src |
created_at | 2019-04-11 16:20:24.545866 |
updated_at | 2019-04-15 12:38:28.93346 |
description | Synchronous network I/O that can be interrupted. |
homepage | https://github.com/Emm54321/cancellable-io |
repository | https://github.com/Emm54321/cancellable-io.git |
max_upload_size | |
id | 127329 |
size | 62,746 |
A crate implementing cancellable synchronous network I/O.
This crate exposes structs TcpStream, TcpListener and UdpSocket that are similar to their std::net variants, except that I/O operations can be cancelled through Canceller objects created with them.
Most methods work as they do in the std::net implementations, and you should refer to the original documentation for details and examples.
Main differences with the original std::net implementations :
Sync
(yet?)use cancellable_io::*;
let (listener, canceller) = TcpListener::bind("127.0.0.1:0").unwrap();
let handle = std::thread::spawn(move || {
println!("Waiting for connections.");
let r = listener.accept();
assert!(is_cancelled(&r.unwrap_err()));
println!("Server cancelled.");
});
std::thread::sleep(std::time::Duration::from_secs(2));
canceller.cancel().unwrap();
handle.join().unwrap();
License: MIT/Apache-2.0