Pasts

Minimal and simpler alternative to the futures crate.

Build Status Docs crates.io

Goals/Features

Table of Contents

Getting Started

Add the following to your Cargo.toml.

toml [dependencies] pasts = "0.3"

Example

This example goes in a loop and prints "One" every second, and "Two" every other second. After 5 prints, the program prints "One" once more, then terminates.

```rust,no_run

![forbid(unsafe_code)]

use pasts::prelude::*; use pasts::ThreadInterrupt;

use std::cell::RefCell;

async fn timerfuture(duration: std::time::Duration) { pasts::spawnblocking(move || std::thread::sleep(duration)).await }

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

async fn two(state: &RefCell) { println!("Starting task two"); loop { timerfuture(std::time::Duration::new(2, 0)).await; let mut state = state.borrowmut(); println!("Two {}", *state); *state += 1; } }

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

fn main() { ThreadInterrupt::block_on(example()); } ```

API

API documentation can be found on docs.rs.

Features

Some APIs are only available with the std feature enabled. They are labeled as such on docs.rs.

Upgrade

You can use the changelog to facilitate upgrading this crate as a dependency.

License

Licensed under either of - Apache License, Version 2.0, (LICENSE-APACHE or https://www.apache.org/licenses/LICENSE-2.0) - Zlib License, (LICENSE-ZLIB or https://opensource.org/licenses/Zlib)

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Contributors are always welcome (thank you for being interested!), whether it be a bug report, bug fix, feature request, feature implementation or whatever. Don't be shy about getting involved. I always make time to fix bugs, so usually a patched version of the library will be out a few days after a report. Features requests will not complete as fast. If you have any questions, design critques, or want me to find you something to work on based on your skill level, you can email me at jeronlau@plopgrizzly.com. Otherwise, here's a link to the issues on GitHub. Before contributing, check out the contribution guidelines, and, as always, make sure to follow the code of conduct.