#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

#129 in Asynchronous

Download history 27859/week @ 2024-03-14 25025/week @ 2024-03-21 24246/week @ 2024-03-28 29496/week @ 2024-04-04 25856/week @ 2024-04-11 26890/week @ 2024-04-18 24489/week @ 2024-04-25 25321/week @ 2024-05-02 25201/week @ 2024-05-09 25736/week @ 2024-05-16 26568/week @ 2024-05-23 28709/week @ 2024-05-30 29371/week @ 2024-06-06 27227/week @ 2024-06-13 28437/week @ 2024-06-20 21461/week @ 2024-06-27

112,311 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–6MB
~21K SLoC