37 stable releases (6 major)

6.2.0 Nov 14, 2023
6.1.0 Jan 30, 2022
5.2.1 Jan 4, 2022
5.2.0 Dec 30, 2021
0.4.2 Oct 31, 2019

#435 in Asynchronous

Download history 39914/week @ 2024-12-08 33865/week @ 2024-12-15 13182/week @ 2024-12-22 15111/week @ 2024-12-29 32607/week @ 2025-01-05 38327/week @ 2025-01-12 32395/week @ 2025-01-19 40836/week @ 2025-01-26 45411/week @ 2025-02-02 41918/week @ 2025-02-09 38859/week @ 2025-02-16 39045/week @ 2025-02-23 38760/week @ 2025-03-02 43845/week @ 2025-03-09 40290/week @ 2025-03-16 37992/week @ 2025-03-23

162,422 downloads per month
Used in 100 crates (3 directly)

BSD-2-Clause

11KB
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

~0.9–5.5MB
~21K SLoC