[−][src]Struct multitask::Executor
A multi-threaded executor.
Implementations
impl Executor
[src]
pub fn new() -> Executor
[src]
pub fn spawn<T: Send + 'static>(
&self,
future: impl Future<Output = T> + Send + 'static
) -> Task<T>
[src]
&self,
future: impl Future<Output = T> + Send + 'static
) -> Task<T>
Spawns a future onto this executor.
Returns a Task
handle for the spawned future.
Examples
use multitask::Executor; let ex = Executor::new(); let task = ex.spawn(async { println!("hello") });
pub fn ticker(&self, notify: impl Fn() + Send + Sync + 'static) -> Ticker
[src]
Creates a new ticker for executing tasks.
In a multi-threaded executor, each executor thread will create its own ticker and then keep
calling Ticker::tick()
in a loop.
Examples
use blocking::block_on; use multitask::Executor; use std::thread; let ex = Executor::new(); // Create two executor threads. for _ in 0..2 { let (p, u) = parking::pair(); let ticker = ex.ticker(move || u.unpark()); thread::spawn(move || { loop { if !ticker.tick() { p.park(); } } }); } // Spawn a future and wait for one of the threads to run it. let task = ex.spawn(async { 1 + 2 }); assert_eq!(block_on(task), 3);
Trait Implementations
impl Debug for Executor
[src]
impl Default for Executor
[src]
impl RefUnwindSafe for Executor
[src]
impl UnwindSafe for Executor
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,