Crates.io | callback-result |
lib.rs | callback-result |
version | 0.1.3 |
source | src |
created_at | 2024-03-20 08:36:59.933456 |
updated_at | 2024-05-11 07:43:58.695274 |
description | Assists in converting the callback function's method of obtaining results into the await method |
homepage | |
repository | https://github.com/wugren/callback-result.git |
max_upload_size | |
id | 1180174 |
size | 17,111 |
Assists in converting the callback function's method of obtaining results into the await method
let waiter = Arc::new(CallbackWaiter::new());
let callback_id = 1;
let result_future = waiter.create_result_future(callback_id);
let tmp_waiter = waiter.clone();
async_std::task::spawn(async move {
async_std::task::sleep(Duration::from_millis(1000)).await;
tmp_waiter.set_result(callback_id, 1);
});
let ret = result_future.await.unwrap();
assert_eq!(ret, 1);