How to share tokio JoinSet across different tasks/threads?

A few tips:

  • You probably should not be using JoinSet here. Instead I recommend CancellationToken for being able to abort tasks, and optionally TaskTracker for being able to wait for them to exit / wait for abort to finish. See graceful shutdown for more info on this.
  • As a general tip, trying to share something with &'static or &'static mut is always always the wrong way, every time.
    • In the case of JoinSet, this type does not come with any utilities for sharing it.
    • You could still do so. Generally, I recommend using the actor pattern for sharing values for most cases.
    • However, if you switch to using TaskTracker, then it does come built-in with utilities for making it easier to share. Specifically, you can share it by cloning it. See the documentation for more info. The same applies to the cancellation token.

Even though I recommend you switch to TaskTracker instead of JoinSet, you can still benefit from the actor pattern with your application. I strongly recommend reading my article about it. Also, the talk about actors (linked in the article) was done after the article, and has more tips than the article itself, so I also recommend my talk.