@@ -14,18 +14,22 @@ impl TaskPoolBuilder {
14
14
Self :: default ( )
15
15
}
16
16
17
+ /// No op on the single threaded task pool
17
18
pub fn num_threads ( self , _num_threads : usize ) -> Self {
18
19
self
19
20
}
20
21
22
+ /// No op on the single threaded task pool
21
23
pub fn stack_size ( self , _stack_size : usize ) -> Self {
22
24
self
23
25
}
24
26
27
+ /// No op on the single threaded task pool
25
28
pub fn thread_name ( self , _thread_name : String ) -> Self {
26
29
self
27
30
}
28
31
32
+ /// Creates a new [`TaskPool`]
29
33
pub fn build ( self ) -> TaskPool {
30
34
TaskPool :: new_internal ( )
31
35
}
@@ -83,16 +87,15 @@ impl TaskPool {
83
87
. collect ( )
84
88
}
85
89
86
- // Spawns a static future onto the JS event loop. For now it is returning FakeTask
87
- // instance with no-op detach method. Returning real Task is possible here, but tricky:
88
- // future is running on JS event loop, Task is running on async_executor::LocalExecutor
89
- // so some proxy future is needed. Moreover currently we don't have long-living
90
- // LocalExecutor here (above `spawn` implementation creates temporary one)
91
- // But for typical use cases it seems that current implementation should be sufficient:
92
- // caller can spawn long-running future writing results to some channel / event queue
93
- // and simply call detach on returned Task (like AssetServer does) - spawned future
94
- // can write results to some channel / event queue.
95
-
90
+ /// Spawns a static future onto the JS event loop. For now it is returning FakeTask
91
+ /// instance with no-op detach method. Returning real Task is possible here, but tricky:
92
+ /// future is running on JS event loop, Task is running on async_executor::LocalExecutor
93
+ /// so some proxy future is needed. Moreover currently we don't have long-living
94
+ /// LocalExecutor here (above `spawn` implementation creates temporary one)
95
+ /// But for typical use cases it seems that current implementation should be sufficient:
96
+ /// caller can spawn long-running future writing results to some channel / event queue
97
+ /// and simply call detach on returned Task (like AssetServer does) - spawned future
98
+ /// can write results to some channel / event queue.
96
99
pub fn spawn < T > ( & self , future : impl Future < Output = T > + ' static ) -> FakeTask
97
100
where
98
101
T : ' static ,
@@ -103,6 +106,7 @@ impl TaskPool {
103
106
FakeTask
104
107
}
105
108
109
+ /// Spawns a static future on the JS event loop. This is exactly the same as [`TaskSpool::spawn`].
106
110
pub fn spawn_local < T > ( & self , future : impl Future < Output = T > + ' static ) -> FakeTask
107
111
where
108
112
T : ' static ,
@@ -115,9 +119,13 @@ impl TaskPool {
115
119
pub struct FakeTask ;
116
120
117
121
impl FakeTask {
122
+ /// No op on the single threaded task pool
118
123
pub fn detach ( self ) { }
119
124
}
120
125
126
+ /// A `TaskPool` scope for running one or more non-`'static` futures.
127
+ ///
128
+ /// For more information, see [`TaskPool::scope`].
121
129
#[ derive( Debug ) ]
122
130
pub struct Scope < ' scope , T > {
123
131
executor : & ' scope async_executor:: LocalExecutor < ' scope > ,
@@ -126,10 +134,22 @@ pub struct Scope<'scope, T> {
126
134
}
127
135
128
136
impl < ' scope , T : Send + ' scope > Scope < ' scope , T > {
137
+ /// Spawns a scoped future onto the thread-local executor. The scope *must* outlive
138
+ /// the provided future. The results of the future will be returned as a part of
139
+ /// [`TaskPool::scope`]'s return value.
140
+ ///
141
+ /// On the single threaded task pool, it just calls [`Scope::spawn_local`].
142
+ ///
143
+ /// For more information, see [`TaskPool::scope`].
129
144
pub fn spawn < Fut : Future < Output = T > + ' scope + Send > ( & mut self , f : Fut ) {
130
145
self . spawn_local ( f) ;
131
146
}
132
147
148
+ /// Spawns a scoped future onto the thread-local executor. The scope *must* outlive
149
+ /// the provided future. The results of the future will be returned as a part of
150
+ /// [`TaskPool::scope`]'s return value.
151
+ ///
152
+ /// For more information, see [`TaskPool::scope`].
133
153
pub fn spawn_local < Fut : Future < Output = T > + ' scope > ( & mut self , f : Fut ) {
134
154
let result = Arc :: new ( Mutex :: new ( None ) ) ;
135
155
self . results . push ( result. clone ( ) ) ;
0 commit comments