[][src]Struct multitask::Executor

pub struct Executor { /* fields omitted */ }

A multi-threaded executor.

Implementations

impl Executor[src]

pub fn new() -> Executor[src]

Creates a new multi-threaded executor.

Examples

use multitask::Executor;

let ex = Executor::new();

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

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

impl Send for Executor

impl Sync for Executor

impl Unpin for Executor

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.