Closed tisonkun closed 3 months ago
Your spawn_executor
function returns a future that does nothing until polled - i.e. the println future is not actually spawned unless you await the future returned from spawn_executor.
@sfackler I got it ... so as long as tokio's spawn called, it can schedule.
May I ask how tokio's spawn keep poll
even if I don't await on the JoinHandle?
That's the whole point of spawn - you're giving the future to the runtime to poll instead of doing it yourself. The only effect calling poll on the JoinHandle has is giving you the return value of the future once it completes.
Version List the versions of all
tokio
crates you are using. The easiest way to get this information is usingcargo tree
subcommand:cargo tree | grep tokio
Platform The output of
uname -a
(UNIX), or version and 32 or 64-bit (Windows)Description Enter your issue details here. One way to structure the description:
runtime.spawn sometimes not run the task passed.
I tried this code:
This can print "hello", while you change the
spawn_executor
to:It doesn't print. Well. This is because I don't
await
. Butruntime.spawn
's docs says:And when I change to:
It can be executed again.
I expected to see this happen:
When calling
spawn_executor
, the future should be scheduled.