#callback #async-await #converting #results #obtaining #async-std #assist

callback-result

Assists in converting the callback function's method of obtaining results into the await method

7 releases

0.2.2 Feb 27, 2025
0.2.1 Feb 27, 2025
0.1.4 Feb 11, 2025
0.1.3 May 11, 2024
0.1.0 Mar 20, 2024

#727 in Asynchronous

Download history 2/week @ 2024-12-04 7/week @ 2024-12-11 60/week @ 2025-02-05 67/week @ 2025-02-12 5/week @ 2025-02-19 312/week @ 2025-02-26 7/week @ 2025-03-05

449 downloads per month

MIT license

18KB
428 lines

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);

Dependencies

~5–14MB
~185K SLoC