Crates.io | pinky-swear |
lib.rs | pinky-swear |
version | 6.2.0 |
source | src |
created_at | 2019-10-28 14:46:43.161142 |
updated_at | 2023-11-14 15:52:34.871423 |
description | Futures and async/await-ready Promises |
homepage | |
repository | https://github.com/amqp-rs/pinky-swear |
max_upload_size | |
id | 176384 |
size | 13,219 |
Simple promise library compatible with std::future
and async/await
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));
}