Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to use !Send futures in warp #528

Open
ancwrd1 opened this issue Apr 9, 2020 · 1 comment
Open

Possibility to use !Send futures in warp #528

ancwrd1 opened this issue Apr 9, 2020 · 1 comment
Labels
feature New feature or request

Comments

@ancwrd1
Copy link

ancwrd1 commented Apr 9, 2020

I have an application which is based internally on Actix actor framework. I would like to refactor it to use warp instead of actix-web, however the issue is the futures incompatibility, because warp expects Send futures and actix uses !Send futures for it's actors.

So the question is whether it is practically doable?

Code example:

async fn status() -> Result<impl warp::Reply, Infallible> {
    let res = RemotingServiceActor::from_registry().send(IsOnlineMsg).await;

    let online = if let Ok(true) = res { "online" } else { "offline" };

    let reply = warp::reply::with_status(online, warp::http::StatusCode::OK);

    Ok(warp::reply::with_header(reply, "Context-Type", "text/html"))
}

...

let status_path = warp::path!("status").and(warp::get()).and_then(status);
commons::spawn(warp::serve(status_path).run(([127, 0, 0, 1], 7311)));

Compilation fails with:

508 |         let status_path = warp::path!("status").and(warp::get()).and_then(status);
    |                                                                  ^^^^^^^^ future returned by `status` is not `Send`
    |
    = help: within `impl core::future::future::Future`, the trait `std::marker::Send` is not implemented for `std::rc::Rc<std::cell::RefCell<std::collections::HashMap<std::string::String, futures_channel::oneshot::Sender<domain::proto::remoting::R_RemoteDelivery>>>>`
note: future is not `Send` as this value is used across an await

181 |     let res = RemotingServiceActor::from_registry().send(IsOnlineMsg).await;
    |               -------------------------------------------------------^^^^^^- `RemotingServiceActor::from_registry().send(IsOnlineMsg)` is later dropped here
    |               |
    |               await occurs here, with `RemotingServiceActor::from_registry().send(IsOnlineMsg)` maybe used later
    |               has type `actix::address::message::Request<services::remoting::RemotingService, message::IsOnlineMsg>`

error: future cannot be sent between threads safely
@seanmonstar
Copy link
Owner

It might be possible to loosen the Send requirements in some places, but probably not quickly.

@jxs jxs added the feature New feature or request label Jul 7, 2020
AzureMarker added a commit to AzureMarker/juniper that referenced this issue Jan 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants