diff --git a/glib/src/functions.rs b/glib/src/functions.rs index d8fcb1b325f3..28ff07f56587 100644 --- a/glib/src/functions.rs +++ b/glib/src/functions.rs @@ -268,9 +268,21 @@ pub fn file_open_tmp( /// where main context is running, e.g. via a `MainLoop`. pub fn spawn_future + Send + 'static>( f: F, +) -> crate::JoinHandle { + spawn_future_with_priority(crate::source::Priority::DEFAULT, f) +} + +// rustdoc-stripper-ignore-next +/// Spawn a new infallible `Future` on the main context, with a non-default priority. +/// +/// This can be called from any thread and will execute the future from the thread +/// where main context is running, e.g. via a `MainLoop`. +pub fn spawn_future_with_priority + Send + 'static>( + priority: crate::source::Priority, + f: F, ) -> crate::JoinHandle { let ctx = crate::MainContext::ref_thread_default(); - ctx.spawn(f) + ctx.spawn_with_priority(priority, f) } // rustdoc-stripper-ignore-next @@ -283,7 +295,22 @@ pub fn spawn_future + Send /// `with_thread_default` or `acquire` on the main context. pub fn spawn_future_local + 'static>( f: F, +) -> crate::JoinHandle { + spawn_future_local_with_priority(crate::source::Priority::DEFAULT, f) +} + +// rustdoc-stripper-ignore-next +/// Spawn a new infallible `Future` on the main context, with a non-default priority. +/// +/// The given `Future` does not have to be `Send`. +/// +/// This can be called only from the thread where the main context is running, e.g. +/// from any other `Future` that is executed on this main context, or after calling +/// `with_thread_default` or `acquire` on the main context. +pub fn spawn_future_local_with_priority + 'static>( + priority: crate::source::Priority, + f: F, ) -> crate::JoinHandle { let ctx = crate::MainContext::ref_thread_default(); - ctx.spawn_local(f) + ctx.spawn_local_with_priority(priority, f) }