Struct hirofa_utils::eventloop::EventLoop
source · pub struct EventLoop { /* private fields */ }
Expand description
the EventLoop struct is a single thread event queue
Implementations§
source§impl EventLoop
impl EventLoop
sourcepub fn is_my_pool_thread(&self) -> bool
pub fn is_my_pool_thread(&self) -> bool
internal method to ensure a member is called from the worker thread
sourcepub fn is_a_pool_thread() -> bool
pub fn is_a_pool_thread() -> bool
internal method to ensure a member is called from the worker thread
sourcepub fn add_local_future_void<F: Future<Output = ()> + 'static>(fut: F)
pub fn add_local_future_void<F: Future<Output = ()> + 'static>(fut: F)
add a future to the EventLoop from within a running task
sourcepub fn add_local_future<R: Send + 'static, F: Future<Output = R> + 'static>(
fut: F,
) -> impl Future<Output = R>
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
sourcepub fn add_local_void<T: FnOnce() + 'static>(task: T)
pub fn add_local_void<T: FnOnce() + 'static>(task: T)
add a task to the EventLoop from within a running task
sourcepub fn add<T: FnOnce() -> R + Send + 'static, R: Send + 'static>(
&self,
task: T,
) -> impl Future<Output = R>
pub fn add<T: FnOnce() -> R + Send + 'static, R: Send + 'static>( &self, task: T, ) -> impl Future<Output = R>
add a task to the EventLoop
sourcepub fn exe<R: Send + 'static, T: FnOnce() -> R + Send + 'static>(
&self,
task: T,
) -> R
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
sourcepub fn add_future<R: Send + 'static, F: Future<Output = R> + Send + 'static>(
&self,
fut: F,
) -> impl Future<Output = R>
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);
sourcepub fn add_future_void<F: Future<Output = ()> + Send + 'static>(&self, fut: F)
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);
sourcepub fn add_timeout<F: FnOnce() + 'static>(task: F, delay: Duration) -> i32
pub fn add_timeout<F: FnOnce() + 'static>(task: F, delay: Duration) -> i32
add a timeout (delayed task) to the EventLoop
sourcepub fn add_interval<F: Fn() + 'static>(
task: F,
delay: Duration,
interval: Duration,
) -> i32
pub fn add_interval<F: Fn() + 'static>( task: F, delay: Duration, interval: Duration, ) -> i32
add an interval (repeated task) to the EventLoop
sourcepub fn clear_timeout(id: i32)
pub fn clear_timeout(id: i32)
cancel a previously added timeout
sourcepub fn clear_interval(id: i32)
pub fn clear_interval(id: i32)
cancel a previously added interval
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventLoop
impl !RefUnwindSafe for EventLoop
impl Send for EventLoop
impl Sync for EventLoop
impl Unpin for EventLoop
impl !UnwindSafe for EventLoop
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more