#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

#280 in Asynchronous

Download history 34522/week @ 2024-07-22 35245/week @ 2024-07-29 37247/week @ 2024-08-05 37581/week @ 2024-08-12 34791/week @ 2024-08-19 35558/week @ 2024-08-26 37870/week @ 2024-09-02 38594/week @ 2024-09-09 33913/week @ 2024-09-16 35293/week @ 2024-09-23 38131/week @ 2024-09-30 33698/week @ 2024-10-07 39025/week @ 2024-10-14 39067/week @ 2024-10-21 33340/week @ 2024-10-28 36520/week @ 2024-11-04

149,451 downloads per month
Used in 82 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