@@ -2,11 +2,12 @@ use std::collections::{
2
2
hash_map:: { IntoIter , Iter } ,
3
3
HashMap ,
4
4
} ;
5
+ use std:: future:: Future ;
5
6
use std:: ops:: { Deref , DerefMut } ;
6
7
use std:: pin:: Pin ;
7
8
use std:: sync:: Arc ;
8
9
9
- use futures :: { self , future, Future , FutureExt } ;
10
+ use futures_util :: { self , future, FutureExt } ;
10
11
use serde_json;
11
12
12
13
use crate :: calls:: {
@@ -197,8 +198,9 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
197
198
/// Handle given request synchronously - will block until response is available.
198
199
/// If you have any asynchronous methods in your RPC it is much wiser to use
199
200
/// `handle_request` instead and deal with asynchronous requests in a non-blocking fashion.
201
+ #[ cfg( feature = "futures-executor" ) ]
200
202
pub fn handle_request_sync ( & self , request : & str , meta : T ) -> Option < String > {
201
- futures :: executor :: block_on ( self . handle_request ( request, meta) )
203
+ futures_executor :: block_on ( self . handle_request ( request, meta) )
202
204
}
203
205
204
206
/// Handle given request asynchronously.
@@ -441,6 +443,7 @@ impl<M: Metadata + Default> IoHandler<M> {
441
443
/// Handle given request synchronously - will block until response is available.
442
444
/// If you have any asynchronous methods in your RPC it is much wiser to use
443
445
/// `handle_request` instead and deal with asynchronous requests in a non-blocking fashion.
446
+ #[ cfg( feature = "futures-executor" ) ]
444
447
pub fn handle_request_sync ( & self , request : & str ) -> Option < String > {
445
448
self . 0 . handle_request_sync ( request, M :: default ( ) )
446
449
}
@@ -485,7 +488,6 @@ fn write_response(response: Response) -> String {
485
488
mod tests {
486
489
use super :: { Compatibility , IoHandler } ;
487
490
use crate :: types:: Value ;
488
- use futures:: future;
489
491
490
492
#[ test]
491
493
fn test_io_handler ( ) {
@@ -515,7 +517,7 @@ mod tests {
515
517
fn test_async_io_handler ( ) {
516
518
let mut io = IoHandler :: new ( ) ;
517
519
518
- io. add_method ( "say_hello" , |_| future :: ready ( Ok ( Value :: String ( "hello" . to_string ( ) ) ) ) ) ;
520
+ io. add_method ( "say_hello" , |_| async { Ok ( Value :: String ( "hello" . to_string ( ) ) ) } ) ;
519
521
520
522
let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"# ;
521
523
let response = r#"{"jsonrpc":"2.0","result":"hello","id":1}"# ;
0 commit comments