Crate pinky_swear[][src]

Expand description

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));
}

Structs

A Pinky allows you to fulfill a Promise that you made.

A PinkyErrorBroadcaster allows you to broacast the success/error of a promise resolution to several subscribers.

A PinkySwear is a Promise that the other party is supposed to honour at some point.

Traits

Sometimes you just cannot keep your Promises.