[−][src]Struct async_executor::Executor
Multi-threaded executor.
The executor does not spawn threads on its own. Instead, you need to call Executor::run()
on manually spawned executor threads.
Examples
use async_channel::unbounded; use async_executor::Executor; use easy_parallel::Parallel; use futures_lite::future; let ex = Executor::new(); let (signal, shutdown) = unbounded::<()>(); Parallel::new() // Run four executor threads. .each(0..4, |_| ex.run(shutdown.recv())) // Run the main future on the current thread. .finish(|| future::block_on(async { println!("Hello world!"); drop(signal); }));
Implementations
impl Executor
[src]
pub fn new() -> Executor
[src]
pub fn spawner(&self) -> Spawner
[src]
Creates a spawner for this executor.
Examples
use async_executor::Executor; let ex = Executor::new(); let spawner = ex.spawner();
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 task onto the executor.
Examples
use async_executor::Executor; let ex = Executor::new(); let task = ex.spawn(async { println!("Hello world"); });
pub fn enter<T>(&self, f: impl FnOnce() -> T) -> T
[src]
Enters the context of an executor.
Examples
use async_executor::{Executor, Task}; let ex = Executor::new(); ex.enter(|| { // `Task::spawn()` now knows which executor to spawn onto. let task = Task::spawn(async { println!("Hello world"); }); });
pub fn run<T>(&self, future: impl Future<Output = T>) -> T
[src]
Runs the executor until the given future completes.
Examples
use async_executor::Executor; let ex = Executor::new(); let task = ex.spawn(async { 1 + 2 }); let res = ex.run(async { task.await * 2 }); assert_eq!(res, 6);
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Executor
impl Send for Executor
impl Sync for Executor
impl Unpin for Executor
impl UnwindSafe for Executor
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>,