stream-cancel
This crate provides a mechanism for interrupting a Stream
.
Any stream can be wrapped in a [Valve
], which enables it to be remotely terminated through an
associated [ValveHandle
]. This can be useful to implement graceful shutdown on "infinite"
streams like a TcpListener
. Once [ValveHandle::close
] is called on the handle for a given
stream's [Valve
], the stream will yield None
to indicate that it has terminated.
extern crate tokio;
use Valve;
use *;
use thread;
let listener = bind.unwrap;
let = new;
let server = spawn;
// the server thread will normally never exit, since more connections
// can always arrive. however, with a Valve, we can turn off the
// stream of incoming connections to initiate a graceful shutdown
exit.close;
server.join.unwrap;