@@ -164,25 +164,7 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
164
164
let request = read_request ( request) ;
165
165
let result = match request {
166
166
Err ( error) => futures:: finished ( Some ( Response :: from ( error, self . compatibility . default_version ( ) ) ) ) . boxed ( ) ,
167
- Ok ( request) => self . middleware . on_request ( request, meta, |request, meta| match request {
168
- Request :: Single ( call) => {
169
- self . handle_call ( call, meta)
170
- . map ( |output| output. map ( Response :: Single ) )
171
- . boxed ( )
172
- } ,
173
- Request :: Batch ( calls) => {
174
- let futures: Vec < _ > = calls. into_iter ( ) . map ( move |call| self . handle_call ( call, meta. clone ( ) ) ) . collect ( ) ;
175
- futures:: future:: join_all ( futures) . map ( |outs| {
176
- let outs: Vec < _ > = outs. into_iter ( ) . filter_map ( |v| v) . collect ( ) ;
177
- if outs. is_empty ( ) {
178
- None
179
- } else {
180
- Some ( Response :: Batch ( outs) )
181
- }
182
- } )
183
- . boxed ( )
184
- } ,
185
- } ) ,
167
+ Ok ( request) => self . handle_rpc_request ( request, meta) ,
186
168
} ;
187
169
188
170
result. map ( |response| {
@@ -192,6 +174,29 @@ impl<T: Metadata, S: Middleware<T>> MetaIoHandler<T, S> {
192
174
} ) . boxed ( )
193
175
}
194
176
177
+ /// Handle deserialized RPC request.
178
+ pub fn handle_rpc_request ( & self , request : Request , meta : T ) -> FutureResponse {
179
+ self . middleware . on_request ( request, meta, |request, meta| match request {
180
+ Request :: Single ( call) => {
181
+ self . handle_call ( call, meta)
182
+ . map ( |output| output. map ( Response :: Single ) )
183
+ . boxed ( )
184
+ } ,
185
+ Request :: Batch ( calls) => {
186
+ let futures: Vec < _ > = calls. into_iter ( ) . map ( move |call| self . handle_call ( call, meta. clone ( ) ) ) . collect ( ) ;
187
+ futures:: future:: join_all ( futures) . map ( |outs| {
188
+ let outs: Vec < _ > = outs. into_iter ( ) . filter_map ( |v| v) . collect ( ) ;
189
+ if outs. is_empty ( ) {
190
+ None
191
+ } else {
192
+ Some ( Response :: Batch ( outs) )
193
+ }
194
+ } )
195
+ . boxed ( )
196
+ } ,
197
+ } )
198
+ }
199
+
195
200
/// Handle single call asynchronously.
196
201
pub fn handle_call ( & self , call : Call , meta : T ) -> BoxFuture < Option < Output > , ( ) > {
197
202
match call {
@@ -261,11 +266,21 @@ impl IoHandler {
261
266
}
262
267
263
268
impl < M : Metadata > IoHandler < M > {
264
- /// Handle given request asynchronously.
269
+ /// Handle given string request asynchronously.
265
270
pub fn handle_request ( & self , request : & str ) -> BoxFuture < Option < String > , ( ) > {
266
271
self . 0 . handle_request ( request, M :: default ( ) )
267
272
}
268
273
274
+ /// Handle deserialized RPC request asynchronously.
275
+ pub fn handle_rpc_request ( & self , request : Request ) -> FutureResponse {
276
+ self . 0 . handle_rpc_request ( request, M :: default ( ) )
277
+ }
278
+
279
+ /// Handle single Call asynchronously.
280
+ pub fn handle_call ( & self , call : Call ) -> BoxFuture < Option < Output > , ( ) > {
281
+ self . 0 . handle_call ( call, M :: default ( ) )
282
+ }
283
+
269
284
/// Handle given request synchronously - will block until response is available.
270
285
/// If you have any asynchronous methods in your RPC it is much wiser to use
271
286
/// `handle_request` instead and deal with asynchronous requests in a non-blocking fashion.
0 commit comments