Add first class shutdown support
- Dominant language
- Rust
- Stars
- 3.7k
- Forks
- 230
- PR merge metrics
- No merged PRs in 30d
Description
I tried calling shutdown in the `readme_sync.rs` example but the rpc server does not shutdown. If I am just using the api incorrectly then I think we should add an example demonstrating how to correctly shutdown the server.
```rust
#![feature(plugin, use_extern_macros, proc_macro_path_invoc)]
#![plugin(tarpc_plugins)]
#[macro_use]
extern crate tarpc;
use std::sync::mpsc;
use std::thread;
use tarpc::sync::{client, server};
use tarpc::sync::client::ClientExt;
use tarpc::util::Never;
use tarpc::futures::*;
service! {
rpc hello(name: String) -> String;
}
#[derive(Clone)]
struct HelloServer;
impl SyncService for HelloServer {
fn hello(&self, name: String) -> Result {
Ok(format!(
"Hello from thread {}, {}!",
thread::current().name().unwrap(),
name
))
}
}
fn main() {
let (tx, rx) = mpsc::channel();
let (shutdown_tx, shutdown_rc) = mpsc::channel();
let handle = thread::spawn(move || {
let handle = HelloServer
.listen("localhost:0", server::Options::default())
.unwrap();
tx.send(handle.addr()).unwrap();
shutdown_tx.send(handle.shutdown());
handle.run();
});
let addr = rx.recv().unwrap();
let shutdown_hook = shutdown_rc.recv().unwrap();
{
let client = SyncClient::connect(addr, client::Options::default()).unwrap();
println!("{}", client.hello("Mom".to_string()).unwrap());
}
let future = shutdown_hook.shutdown();
future.wait().unwrap();
handle.join().unwrap();
}
```
Contributor guide
Assessment
This issue has not been assessed yet.