[][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.6"
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);
    task!(let task_one = one(&state));
    task!(let task_two = two(&state));
    poll![task_one, task_two].await;
}

fn main() {
    exec!(example());
}

Modules

prelude

Re-exported macros.

Macros

exec

Execute futures concurrently; in parallel if the target supports it, otherwise asynchronously.

join

Create a future that waits on multiple futures and returns their results as a tuple.

poll

Create a future that polls multiple futures concurrently.

task

Create future trait object(s) that implement Unpin.

Type Definitions

Task

A pinned future trait object.