-
Notifications
You must be signed in to change notification settings - Fork 276
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
Type erased sync Service #691
Comments
I wonder if you could use this https://docs.rs/sync_wrapper/0.1.1/sync_wrapper/struct.SyncWrapper.html |
It almost works for my use-case, unfortunately it does not implement impl Backend for PostgresBackend {
async fn handle(&self, req: Request) -> Response {
// Can not call inner `Service` with a immutable reference, so need to clone
let svc = self.0.clone();
svc.oneshot().await
}
} I guess one can add |
To convert from a |
No doubt about that. But I think one can still avoid the clone of the inner service with the channel based implementation of the outer service where the outer service is cheap to clone. |
Right so if you do |
Not sure if I understood you correctly, but the buffer outer type would give cheap clones as it doesn't need to clone the inner services. Only "problem" with the current Buffer for my use-case is that it doesn't erase the inner service type, which makes things a bit awkward when I need to store the service on a struct and need the exact type. What I am trying to achieve is a wrapper
|
if you use |
Hi, did you ever come up with a solution to getting a service that is both Clone + Sync? I'm trying to do this:
But I still get this error, saying that it is not Clone:
Even if I make a change to make SyncWrapper Clone (Actyx/sync_wrapper#10) it doesn't work, saying that it doesn't implement Service:
Doing it the other way doesn't work either:
|
Hey,
I was wondering if we could add a
SyncService<Req, Res, Err>
similar toBoxCloneService<Req, Res, Err>
which would additionally implementSync
to the util module? Or is this already easily possible without introducing a new type?I use an implementation in my own project that looks like the code snippet below, it is basically a naive implementation of a type erased version of an unbounded
tower::buffer::Buffer
.With the
SyncService
we can make the code below compile where we need to store a type that implementstower::Service
on a struct that needs to implementSync
. I am not sure how I would make this work with the existing types in the tower crate.I would be happy to open a PR with a more serious implementation if you see the value for it.
The text was updated successfully, but these errors were encountered: