[][src]Crate pasts

Minimal and simpler alternative to the futures crate.

Optional Features

The std feature is enabled by default, disable it to use on no_std.

Getting Started

Add the following to your Cargo.toml:

[dependencies]
pasts = "0.5"
aysnc-std = "1.0"
#![forbid(unsafe_code)]

use pasts::prelude::*;
use async_std::task;

use std::{cell::RefCell, time::Duration};

async fn one(state: &RefCell<usize>) {
    println!("Starting task one");
    while *state.borrow() < 5 {
        task::sleep(Duration::new(1, 0)).await;
        let mut state = state.borrow_mut();
        println!("One {}", *state);
        *state += 1;
    }
    println!("Finish task one");
}

async fn two(state: &RefCell<usize>) {
    println!("Starting task two");
    loop {
        task::sleep(Duration::new(2, 0)).await;
        let mut state = state.borrow_mut();
        println!("Two {}", *state);
        *state += 1;
    }
}

async fn example() {
    let state = RefCell::new(0);
    let mut task_one = one(&state);
    let mut task_two = two(&state);
    let mut tasks = [task_one.fut(), task_two.fut()];
    tasks.select().await;
}

fn main() {
    pasts::spawn(example);
}

Modules

prelude

Re-exported traits

Structs

DynFuture

A wrapper around a Future trait object.

JoinHandle

An owned permission to join on a task (.await on its termination).

Traits

DynFut

Trait for converting Futures into an abstraction of pinned trait objects.

Join

Trait for joining a tuple of futures into a single future.

Select

A trait to select on a slice of Futures.

SelectBoxed

A trait to select on a slice of Pin<Box<Future>>s.

SelectOptional

A trait to select on a slice of Option<Future>s.

Functions

spawn

Execute a future by spawning an asynchronous task.