What happens if all tokio tasks fall into sleep? #5940
-
Hello, I encountered an issue while using Tokio. My code is shown below:
The expected output is as follows:
However, the actual output I'm getting is:
I believe that task2 should wake up from the sleep first and execute before anything else, but the actual code behavior is different from what I expected. Can anyone help me with an explanation? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 2 replies
-
The code you posted will output the correct output. My guess is that the code you posted and the code you actually ran is different. Specifically, I'm guessing that the code you ran used |
Beta Was this translation helpful? Give feedback.
The
tokio_test::task::spawn
utility doesn't do the same thing astokio::spawn
. It's intended for the use-case where you want to control when the task should be polled from the test. Since you never do that, it doesn't get polled.