run_on_main

Function run_on_main 

Source
pub fn run_on_main<F, R>(f: F) -> R
where F: Send + FnOnce(MainThreadMarker) -> R, R: Send,
Expand description

Submit the given closure to the runloop on the main thread.

If the current thread is the main thread, this runs the closure.

The closure is passed a MainThreadMarker that it can further use to access APIs that are only accessible from the main thread.

This function should only be used in applications whose main thread is running an event loop with dispatch_main, UIApplicationMain, NSApplicationMain, CFRunLoop or similar; it will block indefinitely if that is not the case.

ยงExample

use dispatch2::run_on_main;
run_on_main(|mtm| {
    // Do something on the main thread with the given marker
});