pub struct ApplicationHandleThreaded { /* private fields */ }
Expand description

Note: Only available with feature threadsafe enabled.

A thread-safe application handle. This handle also allows you to dispatch code to be executed on the GUI thread from any other thread.

Implementations§

source§

impl ApplicationHandleThreaded

source

pub fn delegate<'a, F, R>(&self, func: F) -> ApplicationDelegateFuture<'a, R>
where F: FnOnce(&ApplicationHandle) -> R + Send + 'a, R: Send,

Executes the given closure func on the GUI thread, and gives back the result when done. This only works when the runtime is still running. If the closure panicked, or the runtime is not running, this will return an error.

The function signature is practically the same as:

pub async fn delegate<'a,F,R>( &self, func: F ) -> Result<R, DelegateError> where
	F: FnOnce( ApplicationHandle ) -> R + Send + 'a,
	R: Send { /* ... */ }

Keep in mind that in multi-threaded environments, it is generally a good idea to put the output on the heap. The output value will be copied.

§Example
let my_value: String = app.delegate(|handle| {
	"string".to_owned()
}).unwrap();
source

pub fn delegate_future<F, R>(&self, future: F) -> DelegateFutureFuture<'_, R>
where F: Future<Output = R> + 'static, R: Send + 'static,

Executes the given future on the GUI thread, and gives back its output when done. This only works when the runtime is still running. If the future panicked during a poll, or the runtime is not running, this will return an error. See also delegate.

The function signature is practically the same as:

pub async fn delegate_future<'a,F,R>( &self, func: F ) -> Result<R, DelegateError> where
	F: Future<Output=R> + 'static,
	R: Send { /* ... */ }
§Example
let my_value: String = app.delegate_future(async {
	"string".to_owned()
}).unwrap();
source

pub fn delegate_async<'a, C, F, R>( &self, func: C ) -> DelegateFutureFuture<'a, R>
where C: FnOnce(ApplicationHandle) -> F + Send + 'a, F: Future<Output = R>, R: Send + 'static,

Executes the given async closure func on the GUI thread, and gives back the result when done. This only works when the runtime is still running. If the closure panicked, or the runtime is not running, this will return an error.

Except, async closures are not yet supported in stable Rust. What we actually mean are closures of the form:

|handle| async move { /* ... */ }

The function signature is practically the same as:

pub async fn delegate_async<'a,C,F,R>( &self, func: C ) -> Result<R, DelegateError> where
	C: FnOnce( ApplicationHandle ) -> F + Send + 'a,
	F: Future<Output=R>,
	R: Send + 'static
{ /* ... */ }
§Example
let my_value: String = app.delegate_async(|handle| async move {
	"String".to_owned()
}).unwrap();
source

pub fn dispatch<'a, F>(&self, func: F) -> bool
where F: FnOnce(&ApplicationHandle) + Send + 'a,

Queues the given closure func to be executed on the GUI thread somewhere in the future. The closure will only execute when and if the runtime is still running. Returns whether or not the closure will be able to execute.

source

pub fn dispatch_delayed<'a, F>(&self, func: F, delay: Duration) -> bool
where F: FnOnce(&ApplicationHandle) + Send + 'a,

Queues the given closure func to be executed on the GUI thread somewhere in the future, at least after the given delay. The closure will only execute when and if the runtime is still running. Returns whether or not the closure will be able to execute.

source

pub fn dispatch_async<'a, C, F>(&self, func: C) -> bool
where C: FnOnce(ApplicationHandle) -> F + Send + 'a, F: Future<Output = ()> + 'static,

Queues the given async closure func to be executed on the GUI thread somewhere in the future. The closure will only execute when and if the runtime is still running. However, there is no guarantee that the whole closure will execute. The runtime might exit when the given closure is at a point of waiting. Returns whether or not the closure will be able to execute its first part.

source

pub fn exit(&self, exit_code: i32)

Signals the runtime to exit. This will cause Runtime::run to stop and return the provided exit code.

source

pub fn spawn<F>(&self, future: F)
where F: Future<Output = ()> + 'static,

Executes the given future on the GUI thread somewhere in the near future.

Methods from Deref<Target = ApplicationHandle>§

source

pub fn cookie_jar(&self) -> Option<CookieJar>

Returns an instance of a CookieJar, if the underlying browser framework supports it. Currently, only CEF supports cookies.

source

pub fn exit(&self, exit_code: i32)

Causes the Runtime to terminate. The Runtime’s Runtime::run or spawn command will return the exit code provided. This will mean that not all tasks might complete. If you were awaiting

source

pub fn spawn<F>(&self, future: F)
where F: Future<Output = ()> + 'static,

Spawns the given future, executing it on the GUI thread somewhere in the near future.

source

pub fn dispatch_delayed<'a, F>(&self, func: F, delay: Duration) -> bool
where F: FnOnce(&ApplicationHandle) + 'a,

Queues the given closure func to be executed on the GUI thread somewhere in the future, at least after the given delay. The closure will only execute when and if the runtime is still running. Returns whether or not the closure will be able to execute.

source

pub async fn sleep(&self, duration: Duration)

Will wait the given duration before returning execution back to the caller. This does not put the current thread in a sleeping state, it just waits.

Trait Implementations§

source§

impl Clone for ApplicationHandleThreaded

source§

fn clone(&self) -> ApplicationHandleThreaded

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl From<ApplicationHandle> for ApplicationHandleThreaded

source§

fn from(other: ApplicationHandle) -> Self

Converts to this type from the input type.
source§

impl Deref for ApplicationHandleThreaded

§

type Target = ApplicationHandle

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Send for ApplicationHandleThreaded

source§

impl Sync for ApplicationHandleThreaded

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<H> HasHandle<H> for H

source§

fn handle(&self) -> &H

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V