mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-05 11:06:11 +01:00
Rework the future Connect trait to only have one method, which takes an Options arg.
This commit is contained in:
@@ -14,14 +14,14 @@ extern crate tokio_proto as tokio;
|
||||
|
||||
use futures::{BoxFuture, Future};
|
||||
use publisher::FutureServiceExt as PublisherExt;
|
||||
use subscriber::FutureServiceExt as SubscriberExt;
|
||||
use std::collections::HashMap;
|
||||
use std::net::SocketAddr;
|
||||
use std::sync::{Arc, Mutex};
|
||||
use std::thread;
|
||||
use std::time::Duration;
|
||||
use tarpc::future::Connect as Fc;
|
||||
use tarpc::sync::Connect as Sc;
|
||||
use subscriber::FutureServiceExt as SubscriberExt;
|
||||
use tarpc::client::future::{Connect as Fc, Options};
|
||||
use tarpc::client::sync::Connect as Sc;
|
||||
use tarpc::util::{FirstSocketAddr, Message, Never};
|
||||
|
||||
pub mod subscriber {
|
||||
@@ -57,12 +57,10 @@ impl subscriber::FutureService for Subscriber {
|
||||
|
||||
impl Subscriber {
|
||||
fn new(id: u32) -> SocketAddr {
|
||||
Subscriber {
|
||||
id: id,
|
||||
}
|
||||
.listen("localhost:0".first_socket_addr())
|
||||
.wait()
|
||||
.unwrap()
|
||||
Subscriber { id: id }
|
||||
.listen("localhost:0".first_socket_addr())
|
||||
.wait()
|
||||
.unwrap()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -88,22 +86,21 @@ impl publisher::FutureService for Publisher {
|
||||
// Ignore failing subscribers.
|
||||
.map(move |client| client.receive(message.clone()).then(|_| Ok(())))
|
||||
.collect::<Vec<_>>())
|
||||
.map(|_| ())
|
||||
.boxed()
|
||||
.map(|_| ())
|
||||
.boxed()
|
||||
}
|
||||
|
||||
type SubscribeFut = BoxFuture<(), Message>;
|
||||
type SubscribeFut = Box<Future<Item = (), Error = Message>>;
|
||||
|
||||
fn subscribe(&self, id: u32, address: SocketAddr) -> Self::SubscribeFut {
|
||||
let clients = self.clients.clone();
|
||||
subscriber::FutureClient::connect(&address)
|
||||
Box::new(subscriber::FutureClient::connect(address, Options::default())
|
||||
.map(move |subscriber| {
|
||||
println!("Subscribing {}.", id);
|
||||
clients.lock().unwrap().insert(id, subscriber);
|
||||
()
|
||||
})
|
||||
.map_err(|e| e.to_string().into())
|
||||
.boxed()
|
||||
.map_err(|e| e.to_string().into()))
|
||||
}
|
||||
|
||||
type UnsubscribeFut = BoxFuture<(), Never>;
|
||||
|
||||
Reference in New Issue
Block a user