Function show_image::try_run_context[][src]

pub fn try_run_context<F, R>(user_task: F) -> ! where
    F: FnOnce(Result<(), GetDeviceError>) -> R + Send + 'static,
    R: Termination
Expand description

Initialize and run the global context and spawn a user task in a new thread.

This function is almost identical to run_context, except that it allows the user task to handle initialization errors. If the initialization of the global context fails, the user task will be executed in the calling thread. If initialization succeeds, the user task is started in a newly spawned thread.

Whether or not initialization succeeded, the process will exit once the user task returns. Any background threads spawned by show-image will be joined before the process exits. It is the responsibility of the user code to join any manually spawned tasks.

It is also possible to run a user task in the same thread as the context. See try_run_context_with_local_task() for more details.

Panics

This function 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.