How to execute future immediately instead of waking task? #5096
-
For a simple delay example here:
Normally inner time thread should wake up the delay future task, and then releated task will be scheduled at least once somewhere. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
No, you cannot schedule a spawned task outside the runtime. |
Beta Was this translation helpful? Give feedback.
-
@liang-kang I think you are misunderstanding how futures work. I would recommend that you read this post here: https://fasterthanli.me/articles/understanding-rust-futures-by-going-way-too-deep Also, in the example here you are spawning a thread to do background work rather than using the tokio time APIs, which are backed by OS APIs like epoll which are designed for asynchronous systems, which would be more efficient. A huge part of why async is more efficient is that you can do more with fewer threads, and skip out on a lot of overhead. What I am getting at here is that even if what you were proposing was doable, it would still be a bad idea. |
Beta Was this translation helpful? Give feedback.
No, you cannot schedule a spawned task outside the runtime.