Struct EventLoopHandler

Source
pub struct EventLoopHandler<Ev> { /* private fields */ }
Expand description

Event Loop wrapper that can be cloned to pass through threads

Implementations§

Source§

impl<Ev> EventLoopHandler<Ev>
where Ev: Send + 'static,

Source

pub fn emit(&self, event: Ev) -> Result<(), Ev>

Triggers an event “Ev” once. Returns the same event if the event loop is not active.

Source

pub fn emit_until<F>(&self, f: F)
where F: Send + 'static + Fn() -> Emit<Ev>,

Triggers an event “Ev” until the return of the “clousure” is None

use asynchronous::{EventLoop, Emit};
 
let el = EventLoop::new();
let x = std::sync::Arc::new(std::sync::Mutex::new(0));
el.emit_until(move || {
   let mut lock_x = x.lock().unwrap(); *lock_x += 1;
   if *lock_x <= 3 { Emit::Event("Event Test") } else { Emit::Stop }
});    
// Do something here
el.finish_in_ms(100).to_promise().finally_sync(|res| {  // res: Result<Vec<Ev>,()>
    assert_eq!(res.unwrap(), vec!["Event Test", "Event Test", "Event Test"]);
});
Source

pub fn is_active(&self) -> bool

Returns true if the event loop is running

Source

pub fn finish(&self)

Finishes the event loop immediately.

Source

pub fn finish_in_ms(&self, duration_ms: u32)

Finishes the event loop in N milliseconds

Trait Implementations§

Source§

impl<Ev> Clone for EventLoopHandler<Ev>

Source§

fn clone(&self) -> EventLoopHandler<Ev>

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

Auto Trait Implementations§

§

impl<Ev> Freeze for EventLoopHandler<Ev>

§

impl<Ev> RefUnwindSafe for EventLoopHandler<Ev>

§

impl<Ev> Send for EventLoopHandler<Ev>
where Ev: Send,

§

impl<Ev> Sync for EventLoopHandler<Ev>
where Ev: Send,

§

impl<Ev> Unpin for EventLoopHandler<Ev>

§

impl<Ev> UnwindSafe for EventLoopHandler<Ev>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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,

Source§

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>,

Source§

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>,

Source§

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.