Skip to content

Commit c3b1042

Browse files
Fix README.md examples to be compilable on current version (#638)
1 parent 771340e commit c3b1042

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

README.md

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ use jsonrpc_derive::rpc;
7777
pub trait Rpc {
7878
/// Adds two numbers and returns a result
7979
#[rpc(name = "add")]
80-
fn add(&self, u64, u64) -> Result<u64>;
80+
fn add(&self, a: u64, b: u64) -> Result<u64>;
8181
}
8282

8383
pub struct RpcImpl;
@@ -97,7 +97,8 @@ fn main() {
9797

9898
```rust
9999
use jsonrpc_core_client::transports::local;
100-
use jsonrpc_core::{Error, IoHandler, Result};
100+
use jsonrpc_core::{BoxFuture, IoHandler, Result};
101+
use jsonrpc_core::futures::{self, future, TryFutureExt};
101102
use jsonrpc_derive::rpc;
102103

103104
/// Rpc trait
@@ -113,7 +114,7 @@ pub trait Rpc {
113114

114115
/// Performs asynchronous operation
115116
#[rpc(name = "callAsync")]
116-
fn call(&self, a: u64) -> FutureResult<String, Error>;
117+
fn call(&self, a: u64) -> BoxFuture<Result<String>>;
117118
}
118119

119120
struct RpcImpl;
@@ -127,19 +128,19 @@ impl Rpc for RpcImpl {
127128
Ok(a + b)
128129
}
129130

130-
fn call(&self, _: u64) -> FutureResult<String, Error> {
131-
future::ok("OK".to_owned())
131+
fn call(&self, _: u64) -> BoxFuture<Result<String>> {
132+
Box::pin(future::ready(Ok("OK".to_owned())))
132133
}
133134
}
134135

135136
fn main() {
136137
let mut io = IoHandler::new();
137138
io.extend_with(RpcImpl.to_delegate());
138139

139-
let fut = {
140-
let (client, server) = local::connect::<gen_client::Client, _, _>(io);
141-
client.add(5, 6).map(|res| println!("5 + 6 = {}", res)).join(server)
142-
};
143-
fut.wait().unwrap();
140+
let (client, server) = local::connect::<gen_client::Client, _, _>(io);
141+
let fut = client.add(5, 6).map_ok(|res| println!("5 + 6 = {}", res));
142+
futures::executor::block_on(async move { futures::join!(fut, server) })
143+
.0
144+
.unwrap();
144145
}
145146
```

0 commit comments

Comments
 (0)