2 个版本 (1 个稳定版本)
1.0.0 | 2023 年 7 月 12 日 |
---|---|
0.0.1 | 2023 年 7 月 12 日 |
#262 在 模拟
5KB
85 行
rs-promise
Rust 中简单的 promise 实现
用法
#[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");
}
}
依赖
~3–9.5MB
~81K SLoC