google / google/tarpc

Add first class shutdown support

Open
#196 8 comments 0 reactions 1 assignee Claimed by @tikue View on GitHub
feature
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

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.