tarpc last attempt

This commit is contained in:
ntr 2018-09-02 13:48:06 +10:00
parent d490ff1024
commit 0012b1b585
2 changed files with 21 additions and 13 deletions

View File

@ -19,8 +19,8 @@ mod battle;
mod skill; mod skill;
mod net; mod net;
use net::server; use net::run_server;
fn main() { fn main() {
server() run_server()
} }

30
src/net.rs Normal file → Executable file
View File

@ -19,7 +19,7 @@ impl FutureService for HelloServer {
} }
} }
pub fn server() { pub fn run_server() {
let mut reactor = reactor::Core::new().unwrap(); let mut reactor = reactor::Core::new().unwrap();
let (mut handle, server) = HelloServer let (mut handle, server) = HelloServer
.listen( .listen(
@ -28,16 +28,24 @@ pub fn server() {
server::Options::default(), server::Options::default(),
) )
.unwrap(); .unwrap();
handle.wait();
reactor.handle().spawn(server); reactor.handle().spawn(server);
}
// let options = client::Options::default().handle(reactor.handle()); #[cfg(test)]
// reactor mod tests {
// .run( use super::*;
// FutureClient::connect(handle.addr(), options)
// .map_err(|e| panic!("{:?}", e)) #[test]
// .and_then(|client| client.hello("Mom".to_string())) fn connect() {
// .map(|resp| println!("{}", resp)), let mut reactor = reactor::Core::new().unwrap();
// ) let options = client::Options::default().handle(reactor.handle());
// .unwrap(); reactor
.run(
FutureClient::connect("localhost:10000".first_socket_addr(), options)
.map_err(|e| panic!("{:?}", e))
.and_then(|client| client.hello("Mom".to_string()))
.map(|resp| println!("{}", resp)),
)
.unwrap();
}
} }