callback-result

Crates.iocallback-result
lib.rscallback-result
version0.1.3
sourcesrc
created_at2024-03-20 08:36:59.933456
updated_at2024-05-11 07:43:58.695274
descriptionAssists in converting the callback function's method of obtaining results into the await method
homepage
repositoryhttps://github.com/wugren/callback-result.git
max_upload_size
id1180174
size17,111
(wugren)

documentation

README

callback-result

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);
Commit count: 7

cargo fmt