Mixing tokio spawn_blocking with tokio_scoped

See: tokio_scoped - Rust

Notice, the docs mention: "Be aware, that when a Scope exits, it will block until every future spawned by the Scope completes. Therefore, one should take caution when creating scopes within an asynchronous context, such as from within another spawned future."

Since blocking is a possibility, what might be a good way to properly block on this tokio_scoped while already within an asynchronous function?

It seems to use block_in_place internally which means it’s technically okay on the multithreaded runtime (as long as you don’t use it inside join!/select!), but really I would not advise using it. lf you really need to run non-'static things concurrently, use FuturesUnordered, or you can just Arc your data enough that the 'static bound doesn’t present a problem.

I would not recommend using crates like that one. Scoped async spawning from within a runtime is fundamentally broken.

Use FuturesUnordered or tokio::join! instead like @SabrinaJewson suggests.

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.