File tree Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Expand file tree Collapse file tree 3 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -5,5 +5,6 @@ pub use crate::error::{GenericError, Result};
55
66pub mod client;
77pub mod common;
8+ pub mod rt;
89
910mod error;
Original file line number Diff line number Diff line change 1+ //! Runtime utilities
2+
3+ /// Implementation of [`hyper::rt::Executor`] that utilises [`tokio::spawn`].
4+ pub mod tokio_executor;
Original file line number Diff line number Diff line change 1+ use hyper:: rt:: Executor ;
2+ use std:: future:: Future ;
3+
4+ /// Future executor that utilises `tokio` threads.
5+ #[ non_exhaustive]
6+ #[ derive( Default , Debug ) ]
7+ pub struct TokioExecutor { }
8+
9+ impl < Fut > Executor < Fut > for TokioExecutor
10+ where
11+ Fut : Future + Send + ' static ,
12+ Fut :: Output : Send + ' static ,
13+ {
14+ fn execute ( & self , fut : Fut ) {
15+ tokio:: spawn ( fut) ;
16+ }
17+ }
18+
19+ impl TokioExecutor {
20+ /// Create new executor that relies on [`tokio::spawn`] to execute futures.
21+ pub fn new ( ) -> Self {
22+ Self { }
23+ }
24+ }
25+
26+ #[ cfg( test) ]
27+ mod tests {
28+ use crate :: rt:: tokio_executor:: TokioExecutor ;
29+ use hyper:: rt:: Executor ;
30+ use tokio:: sync:: oneshot;
31+
32+ #[ cfg( not( miri) ) ]
33+ #[ tokio:: test]
34+ async fn simple_execute ( ) -> Result < ( ) , Box < dyn std:: error:: Error > > {
35+ let ( tx, rx) = oneshot:: channel ( ) ;
36+ let executor = TokioExecutor :: new ( ) ;
37+ executor. execute ( async move {
38+ tx. send ( ( ) ) . unwrap ( ) ;
39+ } ) ;
40+ rx. await . map_err ( Into :: into)
41+ }
42+ }
You can’t perform that action at this time.
0 commit comments