[][src]Struct async_executor::LocalExecutor

pub struct LocalExecutor { /* fields omitted */ }

Single-threaded executor.

The executor can only be run on the thread that created it.

Examples

use async_executor::LocalExecutor;

let local_ex = LocalExecutor::new();

local_ex.run(async {
    println!("Hello world!");
});

Implementations

impl LocalExecutor[src]

pub fn new() -> LocalExecutor[src]

Creates a single-threaded executor.

Examples

use async_executor::LocalExecutor;

let local_ex = LocalExecutor::new();

pub fn spawn<T: 'static>(
    &self,
    future: impl Future<Output = T> + 'static
) -> Task<T>

Important traits for Task<T>

impl<T> Future for Task<T> type Output = T;
[src]

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 run<T>(&self, future: impl Future<Output = T>) -> T[src]

Runs the executor until the given future completes.

Examples

use async_executor::LocalExecutor;

let local_ex = LocalExecutor::new();

let task = local_ex.spawn(async { 1 + 2 });
let res = local_ex.run(async { task.await * 2 });

assert_eq!(res, 6);

Trait Implementations

impl Debug for LocalExecutor[src]

impl Default for LocalExecutor[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.