Crates.io | simulate-promise |
lib.rs | simulate-promise |
version | 1.0.0 |
source | src |
created_at | 2023-07-12 02:05:27.351953 |
updated_at | 2023-07-12 02:13:02.630315 |
description | simulate promise implementation for rust |
homepage | |
repository | https://github.com/Shcarp/rs-promise.git |
max_upload_size | |
id | 914234 |
size | 5,215 |
A simple promise implementation in rust
#[tokio::test]
async fn test() {
let promise = Promise::<String>::new();
let mut promise_clone = promise.clone();
let send_data = "111";
tokio::spawn(async move {
promise_clone.resolve(send_data.to_string()).await.unwrap();
promise_clone.reject(send_data.to_string()).await.unwrap();
});
if let PromiseResult::Resolved(value) = promise.clone().await {
assert_eq!(value, send_data);
} else {
panic!("error");
}
if let PromiseResult::Rejected(value) = promise.clone().await {
assert_eq!(value, send_data);
} else {
panic!("error");
}
}