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

the EventLoop struct is a single thread event queue

Implementations§

source§

impl EventLoop

source

pub fn new() -> Self

init a new EventLoop

source

pub fn is_my_pool_thread(&self) -> bool

internal method to ensure a member is called from the worker thread

source

pub fn is_a_pool_thread() -> bool

internal method to ensure a member is called from the worker thread

source

pub fn add_local_future_void<F: Future<Output = ()> + 'static>(fut: F)

add a future to the EventLoop from within a running task

source

pub fn add_local_future<R: Send + 'static, F: Future<Output = R> + 'static>( fut: F ) -> impl Future<Output = R>

add a future to the EventLoop from within a running task

source

pub fn add_local_void<T: FnOnce() + 'static>(task: T)

add a task to the EventLoop from within a running task

source

pub fn add<T: FnOnce() -> R + Send + 'static, R: Send + 'static>( &self, task: T ) -> impl Future<Output = R>

add a task to the EventLoop

source

pub fn exe<R: Send + 'static, T: FnOnce() -> R + Send + 'static>( &self, task: T ) -> R

execute a task in the EventLoop and block until it completes

source

pub fn add_future<R: Send + 'static, F: Future<Output = R> + Send + 'static>( &self, fut: F ) -> impl Future<Output = R>

add an async block to the EventLoop #Example

use hirofa_utils::eventloop::EventLoop;
use futures::executor::block_on;
let test_loop = EventLoop::new();
let fut = test_loop.add_future(async move {
   // this is an async block, you can .await async functions here
   123
});
let res = block_on(fut); // get result
assert_eq!(res, 123);
source

pub fn add_future_void<F: Future<Output = ()> + Send + 'static>(&self, fut: F)

add a Future to the pool, for when you don’t need the result #Example

use hirofa_utils::eventloop::EventLoop;
use futures::executor::block_on;
use std::sync::mpsc::channel;
let test_loop = EventLoop::new();
let (tx, rx) = channel(); // just to see if it works
let fut = test_loop.add_future(async move {
   // this is an async block, you can .await async functions here
   println!("running async here");
   tx.send(1234);
});

let res = rx.recv().expect("could not recv");
assert_eq!(res, 1234);
source

pub fn add_void<T: FnOnce() + Send + 'static>(&self, task: T)

add a task to the pool

source

pub fn add_timeout<F: FnOnce() + 'static>(task: F, delay: Duration) -> i32

add a timeout (delayed task) to the EventLoop

source

pub fn add_interval<F: Fn() + 'static>( task: F, delay: Duration, interval: Duration ) -> i32

add an interval (repeated task) to the EventLoop

source

pub fn clear_timeout(id: i32)

cancel a previously added timeout

source

pub fn clear_interval(id: i32)

cancel a previously added interval

Trait Implementations§

source§

impl Debug for EventLoop

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Default for EventLoop

source§

fn default() -> Self

Returns the “default value” for a type. Read more
source§

impl Drop for EventLoop

source§

fn drop(&mut self)

Executes the destructor for this type. Read more

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