[−][src]Struct smol::LocalExecutor
A thread-local executor.
The executor can only be run on the thread that created it.
Examples
use async_executor::LocalExecutor; use futures_lite::future; let local_ex = LocalExecutor::new(); future::block_on(local_ex.run(async { println!("Hello world!"); }));
Implementations
impl<'a> LocalExecutor<'a>
[src]
pub const fn new() -> LocalExecutor<'a>
[src]
Creates a single-threaded executor.
Examples
use async_executor::LocalExecutor; let local_ex = LocalExecutor::new();
pub fn spawn<T>(&self, future: impl Future<Output = T> + 'a) -> Task<T>ⓘ where
T: 'a,
[src]
T: 'a,
Spawns a task onto the executor.
Examples
use async_executor::LocalExecutor; let local_ex = LocalExecutor::new(); let task = local_ex.spawn(async { println!("Hello world"); });
pub fn try_tick(&self) -> bool
[src]
Attempts to run a task if at least one is scheduled.
Running a scheduled task means simply polling its future once.
Examples
use async_executor::LocalExecutor; let ex = LocalExecutor::new(); assert!(!ex.try_tick()); // no tasks to run let task = ex.spawn(async { println!("Hello world"); }); assert!(ex.try_tick()); // a task was found
pub async fn tick(&'_ self)
[src]
Run a single task.
Running a task means simply polling its future once.
If no tasks are scheduled when this method is called, it will wait until one is scheduled.
Examples
use async_executor::LocalExecutor; use futures_lite::future; let ex = LocalExecutor::new(); let task = ex.spawn(async { println!("Hello world"); }); future::block_on(ex.tick()); // runs the task
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::LocalExecutor; use futures_lite::future; let local_ex = LocalExecutor::new(); let task = local_ex.spawn(async { 1 + 2 }); let res = future::block_on(local_ex.run(async { task.await * 2 })); assert_eq!(res, 6);
Trait Implementations
impl<'a> Debug for LocalExecutor<'a>
[src]
impl<'a> Default for LocalExecutor<'a>
[src]
pub fn default() -> LocalExecutor<'a>
[src]
impl<'_> RefUnwindSafe for LocalExecutor<'_>
[src]
impl<'_> UnwindSafe for LocalExecutor<'_>
[src]
Auto Trait Implementations
impl<'a> !Send for LocalExecutor<'a>
impl<'a> !Sync for LocalExecutor<'a>
impl<'a> Unpin for LocalExecutor<'a>
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,
pub 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.
pub 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>,