@@ -2,11 +2,12 @@ use std::collections::{
22 hash_map:: { IntoIter , Iter } ,
33 HashMap ,
44} ;
5+ use std:: future:: Future ;
56use std:: ops:: { Deref , DerefMut } ;
67use std:: pin:: Pin ;
78use std:: sync:: Arc ;
89
9- use futures :: { self , future, Future , FutureExt } ;
10+ use futures_util :: { self , future, FutureExt } ;
1011use serde_json;
1112
1213use crate :: calls:: {
@@ -197,8 +198,9 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
197198 /// Handle given request synchronously - will block until response is available.
198199 /// If you have any asynchronous methods in your RPC it is much wiser to use
199200 /// `handle_request` instead and deal with asynchronous requests in a non-blocking fashion.
201+ #[ cfg( feature = "futures-executor" ) ]
200202 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) )
202204 }
203205
204206 /// Handle given request asynchronously.
@@ -441,6 +443,7 @@ impl<M: Metadata + Default> IoHandler<M> {
441443 /// Handle given request synchronously - will block until response is available.
442444 /// If you have any asynchronous methods in your RPC it is much wiser to use
443445 /// `handle_request` instead and deal with asynchronous requests in a non-blocking fashion.
446+ #[ cfg( feature = "futures-executor" ) ]
444447 pub fn handle_request_sync ( & self , request : & str ) -> Option < String > {
445448 self . 0 . handle_request_sync ( request, M :: default ( ) )
446449 }
@@ -485,7 +488,6 @@ fn write_response(response: Response) -> String {
485488mod tests {
486489 use super :: { Compatibility , IoHandler } ;
487490 use crate :: types:: Value ;
488- use futures:: future;
489491
490492 #[ test]
491493 fn test_io_handler ( ) {
@@ -515,7 +517,7 @@ mod tests {
515517 fn test_async_io_handler ( ) {
516518 let mut io = IoHandler :: new ( ) ;
517519
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 ( ) ) ) } ) ;
519521
520522 let request = r#"{"jsonrpc": "2.0", "method": "say_hello", "params": [42, 23], "id": 1}"# ;
521523 let response = r#"{"jsonrpc":"2.0","result":"hello","id":1}"# ;
0 commit comments