@@ -77,7 +77,7 @@ use jsonrpc_derive::rpc;
77
77
pub trait Rpc {
78
78
/// Adds two numbers and returns a result
79
79
#[rpc(name = " add" )]
80
- fn add (& self , u64 , u64 ) -> Result <u64 >;
80
+ fn add (& self , a : u64 , b : u64 ) -> Result <u64 >;
81
81
}
82
82
83
83
pub struct RpcImpl ;
@@ -97,7 +97,8 @@ fn main() {
97
97
98
98
``` rust
99
99
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 };
101
102
use jsonrpc_derive :: rpc;
102
103
103
104
/// Rpc trait
@@ -113,7 +114,7 @@ pub trait Rpc {
113
114
114
115
/// Performs asynchronous operation
115
116
#[rpc(name = " callAsync" )]
116
- fn call (& self , a : u64 ) -> FutureResult < String , Error >;
117
+ fn call (& self , a : u64 ) -> BoxFuture < Result < String > >;
117
118
}
118
119
119
120
struct RpcImpl ;
@@ -127,19 +128,19 @@ impl Rpc for RpcImpl {
127
128
Ok (a + b )
128
129
}
129
130
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 ()) ))
132
133
}
133
134
}
134
135
135
136
fn main () {
136
137
let mut io = IoHandler :: new ();
137
138
io . extend_with (RpcImpl . to_delegate ());
138
139
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 ();
144
145
}
145
146
```
0 commit comments