6
6
//! [Tokio]: https://crates.io/crates/tokio
7
7
//! [async-std]: https://crates.io/crates/async-std
8
8
9
- use std:: { fmt:: Debug , future:: Future , time:: Duration } ;
10
9
use futures_util:: stream:: { unfold, Stream } ;
10
+ use std:: { fmt:: Debug , future:: Future , time:: Duration } ;
11
11
use thiserror:: Error ;
12
12
13
13
/// A runtime is an abstraction of an async runtime like [Tokio] or [async-std]. It allows
@@ -34,15 +34,20 @@ pub trait Runtime: Clone + Send + Sync + 'static {
34
34
/// At the moment, the shutdown happens by blocking the
35
35
/// current thread. This means runtime implementations need to make sure they can still execute
36
36
/// the given future even if the main thread is blocked.
37
- fn spawn < F > ( & self , future : F ) where F : Future < Output = ( ) > + Send + ' static ;
37
+ fn spawn < F > ( & self , future : F )
38
+ where
39
+ F : Future < Output = ( ) > + Send + ' static ;
38
40
39
41
/// Return a future that resolves after the specified [Duration].
40
42
fn delay ( & self , duration : Duration ) -> impl Future < Output = ( ) > + Send + ' static ;
41
43
}
42
44
43
45
/// Uses the given runtime to produce an interval stream.
44
46
#[ cfg( feature = "experimental_async_runtime" ) ]
45
- pub ( crate ) fn to_interval_stream < T : Runtime > ( runtime : T , interval : Duration ) -> impl Stream < Item = ( ) > {
47
+ pub ( crate ) fn to_interval_stream < T : Runtime > (
48
+ runtime : T ,
49
+ interval : Duration ,
50
+ ) -> impl Stream < Item = ( ) > {
46
51
unfold ( ( ) , move |_| {
47
52
let runtime_cloned = runtime. clone ( ) ;
48
53
@@ -70,7 +75,7 @@ pub struct Tokio;
70
75
impl Runtime for Tokio {
71
76
fn spawn < F > ( & self , future : F )
72
77
where
73
- F : Future < Output = ( ) > + Send + ' static
78
+ F : Future < Output = ( ) > + Send + ' static ,
74
79
{
75
80
#[ allow( clippy:: let_underscore_future) ]
76
81
// we don't have to await on the returned future to execute
@@ -111,7 +116,7 @@ pub struct TokioCurrentThread;
111
116
impl Runtime for TokioCurrentThread {
112
117
fn spawn < F > ( & self , future : F )
113
118
where
114
- F : Future < Output = ( ) > + Send + ' static
119
+ F : Future < Output = ( ) > + Send + ' static ,
115
120
{
116
121
// We cannot force push tracing in current thread tokio scheduler because we rely on
117
122
// BatchSpanProcessor to export spans in a background task, meanwhile we need to block the
@@ -150,7 +155,7 @@ pub struct AsyncStd;
150
155
impl Runtime for AsyncStd {
151
156
fn spawn < F > ( & self , future : F )
152
157
where
153
- F : Future < Output = ( ) > + Send + ' static
158
+ F : Future < Output = ( ) > + Send + ' static ,
154
159
{
155
160
#[ allow( clippy:: let_underscore_future) ]
156
161
let _ = async_std:: task:: spawn ( future) ;
0 commit comments