mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-18 09:14:20 +01:00
Finish the multiplex implementation
This commit is contained in:
@@ -10,9 +10,10 @@
|
||||
extern crate tarpc;
|
||||
extern crate futures;
|
||||
|
||||
use futures::{BoxFuture, Future};
|
||||
use add::{FutureService as AddFutureService, FutureServiceExt as AddExt};
|
||||
use double::{FutureService as DoubleFutureService, FutureServiceExt as DoubleExt};
|
||||
use futures::{BoxFuture, Future};
|
||||
use std::sync::{Arc, Mutex};
|
||||
use tarpc::util::{FirstSocketAddr, Message, Never};
|
||||
use tarpc::future::Connect as Fc;
|
||||
use tarpc::sync::Connect as Sc;
|
||||
@@ -46,7 +47,15 @@ impl AddFutureService for AddServer {
|
||||
|
||||
#[derive(Clone)]
|
||||
struct DoubleServer {
|
||||
client: add::FutureClient,
|
||||
client: Arc<Mutex<add::FutureClient>>,
|
||||
}
|
||||
|
||||
impl DoubleServer {
|
||||
fn new(client: add::FutureClient) -> Self {
|
||||
DoubleServer {
|
||||
client: Arc::new(Mutex::new(client))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl DoubleFutureService for DoubleServer {
|
||||
@@ -54,6 +63,8 @@ impl DoubleFutureService for DoubleServer {
|
||||
|
||||
fn double(&self, x: i32) -> Self::DoubleFut {
|
||||
self.client
|
||||
.lock()
|
||||
.unwrap()
|
||||
.add(x, x)
|
||||
.map_err(|e| e.to_string().into())
|
||||
.boxed()
|
||||
@@ -63,7 +74,7 @@ impl DoubleFutureService for DoubleServer {
|
||||
fn main() {
|
||||
let add = AddServer.listen("localhost:0".first_socket_addr()).wait().unwrap();
|
||||
let add_client = add::FutureClient::connect(add.local_addr()).wait().unwrap();
|
||||
let double = DoubleServer { client: add_client };
|
||||
let double = DoubleServer::new(add_client);
|
||||
let double = double.listen("localhost:0".first_socket_addr()).wait().unwrap();
|
||||
|
||||
let double_client = double::SyncClient::connect(double.local_addr()).unwrap();
|
||||
|
||||
Reference in New Issue
Block a user