1
1
//! A batteries included runtime for applications using mobc.
2
2
//! Mobc does not implement runtime, it simply exports runtime.
3
3
4
- pub use runtime :: { DefaultExecutor , Runtime , TaskExecutor } ;
4
+ pub use internal :: { DefaultExecutor , Runtime , TaskExecutor } ;
5
5
6
6
use std:: future:: Future ;
7
7
use std:: pin:: Pin ;
@@ -21,30 +21,30 @@ pub trait Executor: Send + Sync + 'static + Clone {
21
21
}
22
22
23
23
#[ cfg( all( feature = "tokio" , not( feature = "async-std" ) ) ) ]
24
- mod runtime {
24
+ mod internal {
25
25
use super :: * ;
26
26
27
- /// Wrapper of the Tokio Runtime
27
+ /// Wrapper of the Tokio Runtime.
28
28
pub struct Runtime {
29
29
rt : tokio:: runtime:: Runtime ,
30
30
spawner : TaskExecutor ,
31
31
}
32
32
33
33
impl Runtime {
34
- /// Creates a new Runtime
34
+ /// Creates a new [` Runtime`].
35
35
pub fn new ( ) -> Option < Self > {
36
36
Some ( Runtime {
37
37
rt : tokio:: runtime:: Runtime :: new ( ) . unwrap ( ) ,
38
38
spawner : TaskExecutor ,
39
39
} )
40
40
}
41
41
42
- /// Returns a spawner
42
+ /// Returns a spawner.
43
43
pub fn handle ( & self ) -> & TaskExecutor {
44
44
& self . spawner
45
45
}
46
46
47
- /// Run a future to completion on the Tokio runtime. This is the
47
+ /// Runs a future to completion on the Tokio runtime. This is the
48
48
/// runtime's entry point.
49
49
pub fn block_on < F , T > ( & mut self , future : F ) -> T
50
50
where
@@ -53,7 +53,7 @@ mod runtime {
53
53
self . rt . block_on ( future)
54
54
}
55
55
56
- /// Spawn a future onto the Tokio runtime.
56
+ /// Spawns a future onto the Tokio runtime.
57
57
pub fn spawn < F , T > ( & self , future : F )
58
58
where
59
59
F : Future < Output = T > + Send + ' static ,
@@ -63,12 +63,12 @@ mod runtime {
63
63
}
64
64
}
65
65
66
- /// Simple handler for spawning task
66
+ /// Simple handler for spawning task.
67
67
#[ derive( Clone ) ]
68
68
pub struct TaskExecutor ;
69
69
70
70
impl TaskExecutor {
71
- /// Spawn a future onto the Tokio runtime.
71
+ /// Spawns a future onto the Tokio runtime.
72
72
pub fn spawn < F > ( & self , future : F )
73
73
where
74
74
F : Future + Send + ' static ,
@@ -96,15 +96,17 @@ mod runtime {
96
96
}
97
97
}
98
98
99
- #[ cfg( all ( feature = "async-std" ) ) ]
100
- mod runtime {
99
+ #[ cfg( feature = "async-std" ) ]
100
+ mod internal {
101
101
use super :: * ;
102
102
use async_std:: task;
103
103
104
+ /// Simple handler for spawning task.
104
105
#[ derive( Clone ) ]
105
106
pub struct TaskExecutor ;
106
107
107
108
impl TaskExecutor {
109
+ /// Spawns a future onto async-std runtime.
108
110
pub fn spawn < F > ( & self , future : F )
109
111
where
110
112
F : Future + Send + ' static ,
@@ -114,24 +116,30 @@ mod runtime {
114
116
}
115
117
}
116
118
119
+ /// Wrapper of the async-std runtime.
117
120
pub struct Runtime ( TaskExecutor ) ;
118
121
119
122
impl Runtime {
123
+ /// Creates a new [`Runtime`].
120
124
pub fn new ( ) -> Option < Self > {
121
125
Some ( Runtime ( TaskExecutor ) )
122
126
}
123
127
128
+ /// Returns a spawner.
124
129
pub fn handle ( & self ) -> & TaskExecutor {
125
130
& self . 0
126
131
}
127
132
133
+ /// Runs a future to completion on the async-std runtime. This is the
134
+ /// runtime's entry point.
128
135
pub fn block_on < F , T > ( & mut self , future : F ) -> T
129
136
where
130
137
F : Future < Output = T > ,
131
138
{
132
139
task:: block_on ( future)
133
140
}
134
141
142
+ /// Spawns a future onto the async-std runtime.
135
143
pub fn spawn < F , T > ( & self , future : F )
136
144
where
137
145
F : Future < Output = T > + Send + ' static ,
@@ -141,10 +149,12 @@ mod runtime {
141
149
}
142
150
}
143
151
152
+ /// The default executor of async-std.
144
153
#[ derive( Clone ) ]
145
154
pub struct DefaultExecutor ;
146
155
147
156
impl DefaultExecutor {
157
+ /// The default executor of async-std.
148
158
pub fn current ( ) -> Self {
149
159
Self { }
150
160
}
0 commit comments