#futures #promises #async

pinky-swear

Futures and async/await-ready Promises

36 stable releases (6 major)

Uses new Rust 2021

6.1.0 Jan 30, 2022
5.2.1 Jan 4, 2022
5.2.0 Dec 30, 2021
5.1.0 Dec 20, 2020
0.4.2 Oct 31, 2019

#368 in Asynchronous

Download history 9951/week @ 2022-09-28 9650/week @ 2022-10-05 11259/week @ 2022-10-12 11993/week @ 2022-10-19 11630/week @ 2022-10-26 13505/week @ 2022-11-02 12804/week @ 2022-11-09 13221/week @ 2022-11-16 11420/week @ 2022-11-23 10567/week @ 2022-11-30 11980/week @ 2022-12-07 9818/week @ 2022-12-14 6686/week @ 2022-12-21 5972/week @ 2022-12-28 9525/week @ 2023-01-04 9817/week @ 2023-01-11

33,811 downloads per month
Used in 48 crates (2 directly)

BSD-2-Clause

10KB
192 lines

Simple promise library compatible with std::future and async/await

API Docs Build status Downloads

Example

Create a promise and wait for the result while computing the result in another thread

use pinky_swear::{Pinky, PinkySwear};
use std::{thread, time::Duration};

fn compute(pinky: Pinky<Result<u32, ()>>) {
    thread::sleep(Duration::from_millis(1000));
    pinky.swear(Ok(42));
}

fn main() {
    let (promise, pinky) = PinkySwear::new();
    thread::spawn(move || {
        compute(pinky);
    });
    assert_eq!(promise.wait(), Ok(42));
}

lib.rs:

Simple promise library compatible with std::future and async/await

Example

Create a promise and wait for the result while computing the result in another thread

use pinky_swear::{Pinky, PinkySwear};
use std::{thread, time::Duration};

fn compute(pinky: Pinky<Result<u32, ()>>) {
    thread::sleep(Duration::from_millis(1000));
    pinky.swear(Ok(42));
}

fn main() {
    let (promise, pinky) = PinkySwear::new();
    thread::spawn(move || {
        compute(pinky);
    });
    assert_eq!(promise.wait(), Ok(42));
}

Dependencies

~1–5MB
~82K SLoC