[][src]Enum osaka::Task

pub enum Task<R> {
    Later {
        f: Box<dyn Future<R>>,
        a: Again,
    },
    Immediate {
        r: Option<R>,
    },
}

Something that can be activated

An osaka task is usually constructed by adding the osaka macro to a function, like so:

#[osaka]
fn the_answer(poll: osaka::Poll) -> u32 {
    let oracle = Oracle{};
    let token = poll.register(oracle);
    if oracle.is_ready() {
        return 42;
    } else {
        yield poll.again(token);
    }
}

Variants

Later

Fields of Later

f: Box<dyn Future<R>>a: Again
Immediate

Fields of Immediate

r: Option<R>

Methods

impl<R> Task<R>[src]

pub fn run(&mut self) -> R[src]

run a task to completion, blocking the current thread.

this is not re-entrant, meaning you cannot call this function from some callback. It is also not thread safe. Basically only ever call this once, prefferably in main.

pub fn new(f: Box<dyn Future<R>>, a: Again) -> Self[src]

the brave may construct a Task manually from a Future

the passed Again instance needs to already contain an activation source, or the task will never be executed

for example:

struct Santa {
    poll: Poll
}

impl Future for Santa {
    fn poll(&mut self) -> FutureResult<Present> {
        FutureResult::Again(self.poll.never())
    }
}

fn main() {
    let poll = Poll::new();
    let santa = Santa{poll};
    santa.run().unwrap();
}

pub fn wakeup_now(&mut self)[src]

force a wakeup the next time activate is called. This is for a poor implementation of channels and you should probably not use this.

pub fn immediate(t: R) -> Task<R>[src]

Trait Implementations

impl<R> Future<R> for Task<R>[src]

fn poll(&mut self) -> FutureResult<R>[src]

this is called by the execution engine, or a sync macro.

you can call this by hand, but it won't actually do anything unless the task contains a token that is ready, or has an expired deadline

impl<E: Debug> Termination for Task<Result<(), E>>[src]

Auto Trait Implementations

impl<R> !Send for Task<R>

impl<R> !Sync for Task<R>

Blanket Implementations

impl<R, X> Future for X where
    X: Generator<Yield = Again, Return = R> + Unpin
[src]

impl<T> From for T[src]

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

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

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

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

The type returned in the event of a conversion error.