Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Future returned by Serve::serve() is not Send #421

@ditsing

Description

@ditsing

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions