#promise #future #async

pinky-swear

Futures and async/await-ready Promises

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

#235 in Asynchronous

Download history 26819/week @ 2024-01-03 28773/week @ 2024-01-10 30328/week @ 2024-01-17 28812/week @ 2024-01-24 29383/week @ 2024-01-31 32548/week @ 2024-02-07 31669/week @ 2024-02-14 25418/week @ 2024-02-21 26857/week @ 2024-02-28 28731/week @ 2024-03-06 28605/week @ 2024-03-13 25427/week @ 2024-03-20 22500/week @ 2024-03-27 30667/week @ 2024-04-03 26273/week @ 2024-04-10 21694/week @ 2024-04-17

106,062 downloads per month
Used in 76 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

~1–7MB
~21K SLoC