#futures #promises #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

#313 in Asynchronous

Download history 23618/week @ 2023-11-07 23813/week @ 2023-11-14 18501/week @ 2023-11-21 23064/week @ 2023-11-28 24907/week @ 2023-12-05 28094/week @ 2023-12-12 21940/week @ 2023-12-19 10061/week @ 2023-12-26 26822/week @ 2024-01-02 29936/week @ 2024-01-09 29688/week @ 2024-01-16 27870/week @ 2024-01-23 30937/week @ 2024-01-30 31437/week @ 2024-02-06 33926/week @ 2024-02-13 21803/week @ 2024-02-20

123,951 downloads per month
Used in 73 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–7.5MB
~21K SLoC