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

callback-result

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

4 releases

0.1.3 May 11, 2024
0.1.2 Apr 10, 2024
0.1.1 Apr 9, 2024
0.1.0 Mar 20, 2024

#558 in Asynchronous

Download history 134/week @ 2024-03-17 3/week @ 2024-03-24 18/week @ 2024-03-31 265/week @ 2024-04-07 11/week @ 2024-04-14 152/week @ 2024-05-05 35/week @ 2024-05-12 11/week @ 2024-05-19

198 downloads per month

MIT license

16KB
378 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

~4–17MB
~184K SLoC