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
15,028 downloads per month
Used in 26 crates
(2 directly)
10KB
188 lines
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));
}
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