Navigation Menu

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

Client builder's executor setter is confusing for new tokio 0.2 alpha #1944

Closed
zimond opened this issue Sep 17, 2019 · 4 comments · Fixed by #2032
Closed

Client builder's executor setter is confusing for new tokio 0.2 alpha #1944

zimond opened this issue Sep 17, 2019 · 4 comments · Fixed by #2032
Labels
B-rfc Blocked: More comments would be useful in determine next steps.
Milestone

Comments

@zimond
Copy link

zimond commented Sep 17, 2019

Currently in hyper, the Builder::executor<E>() setter requires a for<'a> &'a E: tokio_executor::Executor bound. Which, in latest tokio (=0.2.0-alpha.4), only Sender meets this bound.

However, Sender is now not exported anymore by tokio. There seems to be no easy way to set custom executor.

@seanmonstar
Copy link
Member

Yea, some impls could probably be added to Tokio... However, it seems like the tokio::Executor trait may go away. I've been thinking that instead hyper should just accept impl FnMut(Fut) -> Result<(), E> instead, so as to not need to depend on any external trait.

@seanmonstar seanmonstar added this to the 0.13 milestone Sep 17, 2019
@seanmonstar seanmonstar added the B-rfc Blocked: More comments would be useful in determine next steps. label Sep 17, 2019
@sparky8251
Copy link

I'm currently facing this issue as well.

Code is

let runtime = tokio::runtime::Builder::new().build().unwrap();

let mut https = HttpsConnector::new().unwrap();
https.https_only(true);

let client = hyper::Client::builder()
    .executor(runtime.executor())
    .build::<_, hyper::Body>(https);

Anyone have a good way to work around this issue currently or am I stuck waiting for an official hyper/tokio fix?

@zimond
Copy link
Author

zimond commented Oct 17, 2019

@sparky8251 Currently you need to create a new executor, something like this (not tested):

struct DefaultExecutor(TaskExecutor);


impl Executor for DefaultExecutor {
    fn spawn(
        &mut self,
        future: Pin<Box<dyn Future<Output = ()> + Send>>
    ) -> Result<(), tokio_executor::SpawnError> {
        Ok(self.0.spawn(future))
    }

    fn status(&self) -> Result<(), tokio_executor::SpawnError> {
        self.0.status()
    }
}

impl Executor for &DefaultExecutor {
    fn spawn(
        &mut self,
        future: Pin<Box<dyn Future<Output = ()> + Send>>
    ) -> Result<(), tokio_executor::SpawnError> {
        Ok(self.0.spawn(future))
    }

    fn status(&self) -> Result<(), tokio_executor::SpawnError> {
        self.0.status()
    }
}

seanmonstar added a commit that referenced this issue Nov 15, 2019
Instead of custom executors needing to be `tokio::Executor` or
`tokio::TypedExecutor`, they are now just `Fn`s.

BREAKING CHANGE: Configuring an `executor` for a client or server should
  now pass a closure or function to spawn the future.

Closes #1944
@danieleades
Copy link
Contributor

futures::task::Spawn has landed.

seanmonstar added a commit that referenced this issue Nov 15, 2019
Instead of custom executors needing to be `tokio::Executor` or
`tokio::TypedExecutor`, they are now just `Fn`s.

BREAKING CHANGE: Configuring an `executor` for a client or server should
  now pass a closure or function to spawn the future.

Closes #1944
seanmonstar added a commit that referenced this issue Nov 15, 2019
Instead of custom executors needing to be `tokio::Executor` or
`tokio::TypedExecutor`, they are now just `Fn`s.

BREAKING CHANGE: Configuring an `executor` for a client or server should
  now pass a closure or function to spawn the future.

Closes #1944
seanmonstar added a commit that referenced this issue Dec 4, 2019
The `hyper::rt::Executor` trait allows defining custom executors to be
used with hyper's `Client` and `Server`.

Closes #1944

BREAKING CHANGE: Any type passed to the `executor` builder methods must
  now implement `hyper::rt::Executor`.

  `hyper::rt::spawn` usage should be replaced with `tokio::task::spawn`.

  `hyper::rt::run` usage should be replaced with `#[tokio::main]` or
  managing a `tokio::runtime::Runtime` manually.
seanmonstar added a commit that referenced this issue Dec 4, 2019
The `hyper::rt::Executor` trait allows defining custom executors to be
used with hyper's `Client` and `Server`.

Closes #1944

BREAKING CHANGE: Any type passed to the `executor` builder methods must
  now implement `hyper::rt::Executor`.

  `hyper::rt::spawn` usage should be replaced with `tokio::task::spawn`.

  `hyper::rt::run` usage should be replaced with `#[tokio::main]` or
  managing a `tokio::runtime::Runtime` manually.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
B-rfc Blocked: More comments would be useful in determine next steps.
Projects
None yet
4 participants