[Rust] future created by async block is not `Send`

Hello :wave:

I’m spawning an actor using Tokio, but I have this error I’m not sure how to resolve with .audio_level_observer.add_producer

error: future cannot be sent between threads safely
   --> src/state/worker.rs:367:5
    |
367 |     tokio::spawn(async move { actor.run().await });
    |     ^^^^^^^^^^^^ future created by async block is not `Send`
    |
    = help: the trait `std::marker::Send` is not implemented for `dyn futures::Future<Output = Result<(), RequestError>>`
note: future is not `Send` as it awaits another future which is not `Send`
   --> src/state/worker.rs:284:5
    |
284 | /     self
285 | |       .audio_level_observer
286 | |       .add_producer(options)
    | |____________________________^ await occurs here on type `Pin<Box<dyn futures::Future<Output = Result<(), RequestError>>>>`, which is not `Send`
note: required by a bound in `tokio::spawn`
   --> /Users/remikalbe/.cargo/registry/src/github.com-1ecc6299db9ec823/tokio-1.15.0/src/task/spawn.rs:127:21
    |
127 |         T: Future + Send + 'static,
    |                     ^^^^ required by this bound in `tokio::spawn`

Some context:

WorkerActor {
...
audio_level_observer: mediasoup::audio_level_observer::AudioLevelObserver,
...
}
impl WorkerActor {
...
  async fn try_add_producer_to_audio_level_observer(
    &self,
    producer_id: &ProducerId,
  ) -> Result<(), AppError> {
    let options = mediasoup::rtp_observer::RtpObserverAddProducerOptions::new(*producer_id);
    self
      .audio_level_observer
      .add_producer(options)
      .await
      .map_err(|_| {
        AppError::new(
          Some(String::from(
            "Couldn't add producer to audio level observer.",
          )),
          None,
          AppErrorType::MediasoupError,
          None,
        )
      })?;
    Ok(())
  }
...

Is there any reason for #[async_trait(?Send)] to be without Send?

It wasn’t compiling otherwise, but a few things have changed since, so it might be feasible to relax that restriction.

Sorry for late reply, it was rough few days.

I’ve made a fork and removed the restrictions, it seems to work! (It compiles, and the tests passes).

Nice, feel free to submit a PR.