#futures #async #promises

pinky-swear

Futures and async/await-ready Promises

31 stable releases (5 major)

5.1.0 Dec 20, 2020
5.0.1 Sep 19, 2020
4.4.0 Sep 18, 2020
4.2.3 Jul 28, 2020
0.4.2 Oct 31, 2019

#72 in Asynchronous

Download history 4157/week @ 2020-11-04 2965/week @ 2020-11-11 3358/week @ 2020-11-18 3199/week @ 2020-11-25 3473/week @ 2020-12-02 3188/week @ 2020-12-09 2860/week @ 2020-12-16 1936/week @ 2020-12-23 2421/week @ 2020-12-30 3748/week @ 2021-01-06 3502/week @ 2021-01-13 3444/week @ 2021-01-20 3884/week @ 2021-01-27 4196/week @ 2021-02-03 2994/week @ 2021-02-10 3531/week @ 2021-02-17

15,028 downloads per month
Used in 26 crates (2 directly)

BSD-2-Clause

10KB
188 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
~18K SLoC