@@ -13,6 +13,7 @@ use crate::MainContext;
13
13
use crate :: MainLoop ;
14
14
use crate :: Priority ;
15
15
use crate :: Source ;
16
+ use crate :: SourceId ;
16
17
17
18
// Wrapper around Send Futures and non-Send Futures that will panic
18
19
// if the non-Send Future is polled/dropped from a different thread
@@ -240,8 +241,8 @@ impl MainContext {
240
241
///
241
242
/// This can be called from any thread and will execute the future from the thread
242
243
/// where main context is running, e.g. via a `MainLoop`.
243
- pub fn spawn < F : Future < Output = ( ) > + Send + ' static > ( & self , f : F ) {
244
- self . spawn_with_priority ( crate :: PRIORITY_DEFAULT , f) ;
244
+ pub fn spawn < F : Future < Output = ( ) > + Send + ' static > ( & self , f : F ) -> SourceId {
245
+ self . spawn_with_priority ( crate :: PRIORITY_DEFAULT , f)
245
246
}
246
247
247
248
/// Spawn a new infallible `Future` on the main context.
@@ -251,8 +252,8 @@ impl MainContext {
251
252
/// This can be called only from the thread where the main context is running, e.g.
252
253
/// from any other `Future` that is executed on this main context, or after calling
253
254
/// `with_thread_default` or `acquire` on the main context.
254
- pub fn spawn_local < F : Future < Output = ( ) > + ' static > ( & self , f : F ) {
255
- self . spawn_local_with_priority ( crate :: PRIORITY_DEFAULT , f) ;
255
+ pub fn spawn_local < F : Future < Output = ( ) > + ' static > ( & self , f : F ) -> SourceId {
256
+ self . spawn_local_with_priority ( crate :: PRIORITY_DEFAULT , f)
256
257
}
257
258
258
259
/// Spawn a new infallible `Future` on the main context, with a non-default priority.
@@ -263,10 +264,10 @@ impl MainContext {
263
264
& self ,
264
265
priority : Priority ,
265
266
f : F ,
266
- ) {
267
+ ) -> SourceId {
267
268
let f = FutureObj :: new ( Box :: new ( f) ) ;
268
269
let source = TaskSource :: new ( priority, FutureWrapper :: Send ( f) ) ;
269
- source. attach ( Some ( & * self ) ) ;
270
+ source. attach ( Some ( & * self ) )
270
271
}
271
272
272
273
/// Spawn a new infallible `Future` on the main context, with a non-default priority.
@@ -280,13 +281,13 @@ impl MainContext {
280
281
& self ,
281
282
priority : Priority ,
282
283
f : F ,
283
- ) {
284
+ ) -> SourceId {
284
285
let _acquire = self
285
286
. acquire ( )
286
287
. expect ( "Spawning local futures only allowed on the thread owning the MainContext" ) ;
287
288
let f = LocalFutureObj :: new ( Box :: new ( f) ) ;
288
289
let source = TaskSource :: new ( priority, FutureWrapper :: NonSend ( ThreadGuard :: new ( f) ) ) ;
289
- source. attach ( Some ( & * self ) ) ;
290
+ source. attach ( Some ( & * self ) )
290
291
}
291
292
292
293
/// Runs a new, infallible `Future` on the main context and block until it finished, returning
0 commit comments