#futures #promises #async

pinky-swear

Futures and async/await-ready Promises

34 stable releases (6 major)

Uses new Rust 2021

6.0.0 Jan 4, 2022
5.2.1 Jan 4, 2022
5.2.0 Dec 30, 2021
5.1.0 Dec 20, 2020
0.4.2 Oct 31, 2019

#66 in Asynchronous

Download history 6330/week @ 2021-10-01 7811/week @ 2021-10-08 7337/week @ 2021-10-15 8192/week @ 2021-10-22 5727/week @ 2021-10-29 5400/week @ 2021-11-05 5931/week @ 2021-11-12 5824/week @ 2021-11-19 6004/week @ 2021-11-26 5609/week @ 2021-12-03 6441/week @ 2021-12-10 4550/week @ 2021-12-17 3179/week @ 2021-12-24 4959/week @ 2021-12-31 6394/week @ 2022-01-07 6007/week @ 2022-01-14

21,339 downloads per month
Used in 33 crates (3 directly)

BSD-2-Clause

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

~1MB
~20K SLoC

a