[−][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 |
JoinHandle | An owned permission to join on a task ( |
Traits
DynFut | Trait for converting |
Join | Trait for joining a tuple of futures into a single future. |
Select | A trait to select on a slice of |
SelectBoxed | A trait to select on a slice of |
SelectOptional | A trait to select on a slice of |
Functions
spawn | Execute a future by spawning an asynchronous task. |