GithubHelp home page GithubHelp logo

Comments (1)

jonhoo avatar jonhoo commented on July 22, 2024

I'll try to persist some of my thoughts from the Gitter about this change, and also how it interacts with #118.

The proposed solution here is basically:

struct Buffer<T, Request, Executor = DefaultExecutor>
where T: Service<Request>
{
    executor: Executor,
    worker: Option<Worker<T, Request>>,
    // ...
}

And then have poll_ready be:

fn poll_ready(...) -> ... {
    if let Some(w) = self.worker.take() {
        self.executor.spawn(w);
    }
    // ...
}

With #118, the T: Service bound on Worker has to become T: DirectService<Request> instead. To allow Buffer to wrap regular Services, we also provide a DirectedService<T: Service> wrapper that impl DirectService by proxying poll_ready and call to T and doing nothing for the other methods. But Buffer<T> must now have the bound T: DirectService<Request> if it is to contain the Worker instance. While the user can specify that type, they'll have to know about DirectService and the DirectedService wrapper, which seems unfortunate. I don't have a clean workaround for this that doesn't involve Boxing the Worker.


As for hiding the concrete task type that needs to be spawned using this approach, I'm not sure how the solution outlined there fixes issue I raise above? We basically already have the proposed wrapper type (Worker ~= MyLibTask), but this still doesn't hide Worker (due to the E: TypedExecutor<MyLibTask<T> bound). It also still reveals the T: DirectService bound, and the DirectedService wrapper, which seems unfortunate. I don't have a way of getting around that though sadly.

One alternative specifically for the DefaultExecutor case would be to have Buffer::new use future::lazy and return impl Future<Item = Buffer>. It's definitely a bit of a cop-out, but saves us from some of these thorny issues.


And finally, isn't it a little sad for Buffer to carry along an Executor? It probably doesn't matter too much for DefaultExecutor, but are there other Executors where this might be a problem?


Overall, I think we should probably wait to make this change until after #118 lands.

from tower.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.