adnanademovic/simetry

Cannot use Client::connect in a background task

Closed this issue · 4 comments

Hi,

I cannot seem to use Client::connect in a background tokio task:

#[tokio::main]
async fn main() {
  tokio::spawn(async move {
    let mut client = Client::connect(Duration::from_secs(1)).await;
    // do some iRacing stuff
  });

  // do something else
}

The error is: future is not Send as this value is used across an await, caused by `src\iracing\client.rs:267``:

image

Well that's annoying.

I won't have a chance in the next few days to investigate, but once I do I'll try to get things to implement Send/Sync where possible.

I've added a compiles_if_send_is_valid test to prevent a regression like this from happening in the future.

I've released version 0.2.1 that has this issue fixed.

For future reference, it's the usual footgun of the scope of an unsendable value going through an await, even though its actual lifetime is shorter.

Once you verify that the new version works for you, please close the issue.

Works like a charm now. Thanks a bunch