+In a sense, asynchronous function just pass the buck, this buck is simply the fact that, when executing a synchronous function: the caller only resumes when the operation is completed, what if we want our thread to do something else while the operating system is doing his work, we will need to use new I/O library that provides an asynchronous version of this function, Rust approach of supporting asynchronous operation is by introducing a trait, std::future::Future. A Future represent an operation you can test for completion. So with Future, you can always know the state of the current thread inother to do other jobs, but using futures seems challenging because, you keep on polling other jobs while a future is still pending, keeping track of previous futures who are pending and what should be done once there are finished and poll it again, and this somehow ruin the simplicity of the function. Good news, asynchronous function is there, this buck is solved using .await expression which pause the execution of this async function until the awaited value is ready before resuming back it execution. it's true that it easy to get the value of an async function: just await it. But async function itself return a future, so it's now the caller's job to do the polling somehow, thus someone has to wait for value and in this case block_on is our waiter.
0 commit comments