Skip to content

Commit f15c3a3

Browse files
committed
glib: make spawn*() return the SourceId
Signed-off-by: Marc-André Lureau <[email protected]>
1 parent 9048b97 commit f15c3a3

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

glib/src/main_context_futures.rs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::MainContext;
1313
use crate::MainLoop;
1414
use crate::Priority;
1515
use crate::Source;
16+
use crate::SourceId;
1617

1718
// Wrapper around Send Futures and non-Send Futures that will panic
1819
// if the non-Send Future is polled/dropped from a different thread
@@ -240,8 +241,8 @@ impl MainContext {
240241
///
241242
/// This can be called from any thread and will execute the future from the thread
242243
/// 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)
245246
}
246247

247248
/// Spawn a new infallible `Future` on the main context.
@@ -251,8 +252,8 @@ impl MainContext {
251252
/// This can be called only from the thread where the main context is running, e.g.
252253
/// from any other `Future` that is executed on this main context, or after calling
253254
/// `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)
256257
}
257258

258259
/// Spawn a new infallible `Future` on the main context, with a non-default priority.
@@ -263,10 +264,10 @@ impl MainContext {
263264
&self,
264265
priority: Priority,
265266
f: F,
266-
) {
267+
) -> SourceId {
267268
let f = FutureObj::new(Box::new(f));
268269
let source = TaskSource::new(priority, FutureWrapper::Send(f));
269-
source.attach(Some(&*self));
270+
source.attach(Some(&*self))
270271
}
271272

272273
/// Spawn a new infallible `Future` on the main context, with a non-default priority.
@@ -280,13 +281,13 @@ impl MainContext {
280281
&self,
281282
priority: Priority,
282283
f: F,
283-
) {
284+
) -> SourceId {
284285
let _acquire = self
285286
.acquire()
286287
.expect("Spawning local futures only allowed on the thread owning the MainContext");
287288
let f = LocalFutureObj::new(Box::new(f));
288289
let source = TaskSource::new(priority, FutureWrapper::NonSend(ThreadGuard::new(f)));
289-
source.attach(Some(&*self));
290+
source.attach(Some(&*self))
290291
}
291292

292293
/// Runs a new, infallible `Future` on the main context and block until it finished, returning

0 commit comments

Comments
 (0)