Function show_image::run_context_with_local_task[][src]

pub fn run_context_with_local_task<F>(user_task: F) -> ! where
    F: FnOnce(&mut ContextHandle<'_>) + Send + 'static, 
Expand description

Initialize and run the global context and run a user task, both in the main thread.

The global context will execute the user function in the main thread after the context is fully initialized.

This function never returns. The global context will keep running after the local task finishes. It is up to the user code to call std::process::exit when the process should exit. Alternatively, you could call ContextHandle::set_exit_with_last_window.

Note: You should not run a function that blocks for any significant time in the main thread. Doing so will prevent the event loop from processing events and will result in unresponsive windows.

If you’re looking for a place to run your own application code, you probably want to use run_context or the main macro. However, if you can drive your entire application from event handlers, then this function is probably what you’re looking for.

Panics

This function panics if initialization of the global context fails. See try_run_context_with_local_task for a variant that allows the user task to handle initialization errors.

This function also panics if it is called from any thread other than the main thread. Some platforms like OS X require all GUI code to run in the main thread. To ensure portability, this restriction is also enforced on other platforms.