mirror of
https://github.com/OMGeeky/tarpc.git
synced 2026-01-10 13:34:03 +01:00
Update Cargo.toml to use crates.io releases of tokio deps.
This commit is contained in:
@@ -50,7 +50,7 @@ impl Server {
|
||||
impl FutureService for Server {
|
||||
type ReadFut = CpuFuture<Vec<u8>, Never>;
|
||||
|
||||
fn read(&mut self, size: u32) -> Self::ReadFut {
|
||||
fn read(&self, size: u32) -> Self::ReadFut {
|
||||
let request_number = self.request_count.fetch_add(1, Ordering::SeqCst);
|
||||
debug!("Server received read({}) no. {}", size, request_number);
|
||||
self.pool
|
||||
@@ -88,13 +88,13 @@ struct Stats {
|
||||
max: Option<Duration>,
|
||||
}
|
||||
|
||||
fn run_once(mut clients: Vec<FutureClient>, concurrency: u32) -> impl Future<Item=(), Error=()> + 'static {
|
||||
fn run_once(clients: Vec<FutureClient>, concurrency: u32) -> impl Future<Item=(), Error=()> + 'static {
|
||||
let start = Instant::now();
|
||||
let num_clients = clients.len();
|
||||
futures::stream::futures_unordered((0..concurrency as usize)
|
||||
.map(|iteration| (iteration + 1, iteration % num_clients))
|
||||
.map(|(iteration, client_idx)| {
|
||||
let mut client = &mut clients[client_idx];
|
||||
let client = &clients[client_idx];
|
||||
let start = Instant::now();
|
||||
debug!("Client {} reading (iteration {})...", client_idx, iteration);
|
||||
client.read(CHUNK_SIZE)
|
||||
|
||||
@@ -49,7 +49,7 @@ struct Subscriber {
|
||||
impl subscriber::FutureService for Subscriber {
|
||||
type ReceiveFut = futures::Finished<(), Never>;
|
||||
|
||||
fn receive(&mut self, message: String) -> Self::ReceiveFut {
|
||||
fn receive(&self, message: String) -> Self::ReceiveFut {
|
||||
println!("{} received message: {}", self.id, message);
|
||||
futures::finished(())
|
||||
}
|
||||
@@ -80,7 +80,7 @@ impl Publisher {
|
||||
impl publisher::FutureService for Publisher {
|
||||
type BroadcastFut = BoxFuture<(), Never>;
|
||||
|
||||
fn broadcast(&mut self, message: String) -> Self::BroadcastFut {
|
||||
fn broadcast(&self, message: String) -> Self::BroadcastFut {
|
||||
futures::collect(self.clients
|
||||
.lock()
|
||||
.unwrap()
|
||||
@@ -94,7 +94,7 @@ impl publisher::FutureService for Publisher {
|
||||
|
||||
type SubscribeFut = BoxFuture<(), Message>;
|
||||
|
||||
fn subscribe(&mut self, id: u32, address: SocketAddr) -> Self::SubscribeFut {
|
||||
fn subscribe(&self, id: u32, address: SocketAddr) -> Self::SubscribeFut {
|
||||
let clients = self.clients.clone();
|
||||
subscriber::FutureClient::connect(&address)
|
||||
.map(move |subscriber| {
|
||||
@@ -108,7 +108,7 @@ impl publisher::FutureService for Publisher {
|
||||
|
||||
type UnsubscribeFut = BoxFuture<(), Never>;
|
||||
|
||||
fn unsubscribe(&mut self, id: u32) -> Self::UnsubscribeFut {
|
||||
fn unsubscribe(&self, id: u32) -> Self::UnsubscribeFut {
|
||||
println!("Unsubscribing {}", id);
|
||||
self.clients.lock().unwrap().remove(&id).unwrap();
|
||||
futures::finished(()).boxed()
|
||||
@@ -122,7 +122,7 @@ fn main() {
|
||||
.wait()
|
||||
.unwrap();
|
||||
|
||||
let mut publisher_client = publisher::SyncClient::connect(publisher_addr).unwrap();
|
||||
let publisher_client = publisher::SyncClient::connect(publisher_addr).unwrap();
|
||||
|
||||
let subscriber1 = Subscriber::new(0);
|
||||
publisher_client.subscribe(0, subscriber1).unwrap();
|
||||
|
||||
@@ -39,7 +39,7 @@ impl Error for NoNameGiven {
|
||||
struct HelloServer;
|
||||
|
||||
impl SyncService for HelloServer {
|
||||
fn hello(&mut self, name: String) -> Result<String, NoNameGiven> {
|
||||
fn hello(&self, name: String) -> Result<String, NoNameGiven> {
|
||||
if name == "" {
|
||||
Err(NoNameGiven)
|
||||
} else {
|
||||
|
||||
@@ -46,7 +46,7 @@ impl Service for HelloServer {
|
||||
type Error = io::Error;
|
||||
type Future = Box<Future<Item = tarpc::Response<String, Never>, Error = io::Error>>;
|
||||
|
||||
fn call(&mut self, request: Self::Request) -> Self::Future {
|
||||
fn call(&self, request: Self::Request) -> Self::Future {
|
||||
Ok(Ok(format!("Hello, {}!", request.unwrap()))).into_future().boxed()
|
||||
}
|
||||
}
|
||||
@@ -60,7 +60,7 @@ impl FutureClient {
|
||||
tarpc::Client::connect_remotely(addr, &tarpc::future::REMOTE).map(FutureClient)
|
||||
}
|
||||
|
||||
pub fn hello(&mut self, name: String)
|
||||
pub fn hello(&self, name: String)
|
||||
-> impl Future<Item = String, Error = tarpc::Error<Never>> + 'static
|
||||
{
|
||||
self.0.call(name).then(|msg| msg.unwrap())
|
||||
@@ -73,7 +73,7 @@ fn main() {
|
||||
let addr = HelloServer::listen("localhost:10000".first_socket_addr()).wait().unwrap();
|
||||
let f = FutureClient::connect(&addr)
|
||||
.map_err(tarpc::Error::from)
|
||||
.and_then(|mut client| {
|
||||
.and_then(|client| {
|
||||
let resp1 = client.hello("Mom".to_string());
|
||||
info!("Sent first request.");
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ struct HelloServer;
|
||||
impl FutureService for HelloServer {
|
||||
type HelloFut = futures::Finished<String, Never>;
|
||||
|
||||
fn hello(&mut self, name: String) -> Self::HelloFut {
|
||||
fn hello(&self, name: String) -> Self::HelloFut {
|
||||
futures::finished(format!("Hello, {}!", name))
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ fn main() {
|
||||
core.run(
|
||||
FutureClient::connect(&addr)
|
||||
.map_err(tarpc::Error::from)
|
||||
.and_then(|mut client| client.hello("Mom".to_string()))
|
||||
.and_then(|client| client.hello("Mom".to_string()))
|
||||
.map(|resp| println!("{}", resp))
|
||||
).unwrap();
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ service! {
|
||||
struct HelloServer;
|
||||
|
||||
impl SyncService for HelloServer {
|
||||
fn hello(&mut self, name: String) -> Result<String, Never> {
|
||||
fn hello(&self, name: String) -> Result<String, Never> {
|
||||
Ok(format!("Hello, {}!", name))
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,6 @@ impl SyncService for HelloServer {
|
||||
fn main() {
|
||||
let addr = "localhost:10000";
|
||||
HelloServer.listen(addr).unwrap();
|
||||
let mut client = SyncClient::connect(addr).unwrap();
|
||||
let client = SyncClient::connect(addr).unwrap();
|
||||
println!("{}", client.hello("Mom".to_string()).unwrap());
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ struct AddServer;
|
||||
impl AddFutureService for AddServer {
|
||||
type AddFut = futures::Finished<i32, Never>;
|
||||
|
||||
fn add(&mut self, x: i32, y: i32) -> Self::AddFut {
|
||||
fn add(&self, x: i32, y: i32) -> Self::AddFut {
|
||||
futures::finished(x + y)
|
||||
}
|
||||
}
|
||||
@@ -62,7 +62,7 @@ impl DoubleServer {
|
||||
impl DoubleFutureService for DoubleServer {
|
||||
type DoubleFut = BoxFuture<i32, Message>;
|
||||
|
||||
fn double(&mut self, x: i32) -> Self::DoubleFut {
|
||||
fn double(&self, x: i32) -> Self::DoubleFut {
|
||||
self.client
|
||||
.lock()
|
||||
.unwrap()
|
||||
|
||||
@@ -44,7 +44,7 @@ struct Server;
|
||||
impl FutureService for Server {
|
||||
type ReadFut = futures::Finished<Arc<Vec<u8>>, Never>;
|
||||
|
||||
fn read(&mut self) -> Self::ReadFut {
|
||||
fn read(&self) -> Self::ReadFut {
|
||||
futures::finished(BUF.clone())
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ struct Bar;
|
||||
impl bar::FutureService for Bar {
|
||||
type BarFut = futures::Finished<i32, Never>;
|
||||
|
||||
fn bar(&mut self, i: i32) -> Self::BarFut {
|
||||
fn bar(&self, i: i32) -> Self::BarFut {
|
||||
futures::finished(i)
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,7 @@ struct Baz;
|
||||
impl baz::FutureService for Baz {
|
||||
type BazFut = futures::Finished<String, Never>;
|
||||
|
||||
fn baz(&mut self, s: String) -> Self::BazFut {
|
||||
fn baz(&self, s: String) -> Self::BazFut {
|
||||
futures::finished(format!("Hello, {}!", s))
|
||||
}
|
||||
}
|
||||
@@ -61,8 +61,8 @@ fn main() {
|
||||
let bar_addr = Bar.listen("localhost:0".first_socket_addr()).wait().unwrap();
|
||||
let baz_addr = Baz.listen("localhost:0".first_socket_addr()).wait().unwrap();
|
||||
|
||||
let mut bar_client = bar::SyncClient::connect(&bar_addr).unwrap();
|
||||
let mut baz_client = baz::SyncClient::connect(&baz_addr).unwrap();
|
||||
let bar_client = bar::SyncClient::connect(&bar_addr).unwrap();
|
||||
let baz_client = baz::SyncClient::connect(&baz_addr).unwrap();
|
||||
|
||||
info!("Result: {:?}", bar_client.bar(17));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user