I am trying to make an asynchronous TCP server with tokio and get this weird error while trying to spawn a thread
tokio::spawn(accept_conn(client, bc_sender.clone(), bc_sender.subscribe())
^^^^^^^^^^^^ `(dyn std::error::Error + 'static)` cannot be sent between threads safely
I do not see any Error trait object here (the accept_conn
function is async and returns ()) and do not understand why am I sending it
Here is a code snipped which triggers the error:
while let Ok((client, addr)) = listener.accept().await {
info!("New connection, address {}", addr.ip());
tokio::spawn(accept_conn(client, bc_sender.clone(),
bc_sender.subscribe()));
};
And an accept_conn function declaration
async fn accept_conn(client: TcpStream,
cast_sender: broadcast::Sender<PixelChangedEvent>,
cast_receiver: broadcast::Receiver<PixelChangedEvent>) { ... }