[−][src]Struct smol::Executor
An async executor.
Examples
A multi-threaded executor:
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, |_| future::block_on(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 const fn new() -> Executor
[src]
pub fn spawn<T>(
&self,
future: impl Send + Future<Output = T> + 'static
) -> Task<T>ⓘ where
T: 'static + Send,
[src]
&self,
future: impl Send + Future<Output = T> + 'static
) -> Task<T>ⓘ where
T: 'static + Send,
Spawns a task onto the executor.
Examples
use async_executor::Executor; let ex = Executor::new(); let task = ex.spawn(async { println!("Hello world"); });
pub async fn run<T>(&'_ self, future: impl Future<Output = T>) -> T
[src]
Runs the executor until the given future completes.
Examples
use async_executor::Executor; use futures_lite::future; let ex = Executor::new(); let task = ex.spawn(async { 1 + 2 }); let res = future::block_on(ex.run(async { task.await * 2 })); assert_eq!(res, 6);
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>,