- 
                Notifications
    
You must be signed in to change notification settings  - Fork 214
 
Open
Description
I'm trying to write a function that starts a server with a clonable Serve.
async fn start_tarpc_server<ServeFn>(
    addr: SocketAddr,
    serve: ServeFn,
) -> std::io::Result<()>
    where
        ServeFn:
        tarpc::server::Serve + Send + 'static + Clone,
        ServeFn::Req: Send + 'static + serde::de::DeserializeOwned,
        ServeFn::Resp: Send + 'static + serde::ser::Serialize,
{
    tokio::spawn(serve.serve());
    Ok(())
}
That turns out to be impossible because I cannot call tokio::spawn() on the future returned by Serve::serve. The future is not guaranteed to be Send. Same applies to any future that wraps a serve() future.
This is a well-known problem caused by using aysnc fn in public traits. There is a solution described in the same article. Can we apply the solution here?
DCNick3
Metadata
Metadata
Assignees
Labels
No labels