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