Tokio runtime -- wait for all tasks to finish?

  1. I create a Runtime in tokio::runtime - Rust

  2. I spawn a numbed rof tasks using the Runtime

  3. Is there a way to say: block current OS thread unril all async tasks in Runtime finishes ?

Will the shutdown_timeout with Duration::MAX as timeout work for you?

This constraint gives it a value of about 584,942,417,355 years in practice,

This is good enough for my needs; but is this the 'right' way to do it? This feels bit hacky.

Actually, this doesn't work -- shutdown_timeout adds Duration::MAX, causing overflow.

The shutdown methods probably don't do what you want - all of the tasks are cancelled and all they are waiting for is their destructors (and spawn_blocking tasks, which cannot be cancelled).

Tokio doesn't have a general way to actually wait for all tasks, unfortunately.

1 Like

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.