tokeio asynchronous function must be executed with 'await' #6989
-
The tokeio asynchronous function must be executed with 'await'. If it is not executed without 'await', it will never be executed. If it must be executed with 'await', what is the difference between it and a synchronous function? As shown in the following code, the println of the body of the asynchronous function hello-world always fails to execute async fn hello_world(){ } |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Futures in Rust are lazy. An async function or block effectively builds a state machine which is evaluated when awaited (which basically joins the awaited future as a subcomponent of the awaiting future) or spawned on a runtime. Async/await is best thought of as syntactic sugar for building state machines that can be polled to be advanced, and woken for later resumption. A future is an object representing a computation that can be advanced until it needs to wait for an IO event, at which point it will need to be polled again by a runtime. |
Beta Was this translation helpful? Give feedback.
Futures in Rust are lazy. An async function or block effectively builds a state machine which is evaluated when awaited (which basically joins the awaited future as a subcomponent of the awaiting future) or spawned on a runtime. Async/await is best thought of as syntactic sugar for building state machines that can be polled to be advanced, and woken for later resumption.
A future is an object representing a computation that can be advanced until it needs to wait for an IO event, at which point it will need to be polled again by a runtime.