Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9287377

Browse files
committedMar 11, 2025·
refactor(stack/switch_ready): use Either<A, B> future
this commit makes a noöp change to the `SwitchReady<A, B>` machinery provided by our `linkerd-stack` library. this commit is a small refactor that is intended to pave the way for an impending upgrade to tower v0.5, which notably includes breaking changes to the `tower::util::Either<A, B>` service. as of tower v0.5, by way of tower-rs/tower#637, the `Either<A, B>` service is no longer itself a `Future`. so, we can instead use the future provided by `futures`. for more information, see: * linkerd/linkerd2#8733 * #3504 * https://github.com/linkerd/linkerd2-proxy/pull/3504/files#r1988082658 * tower-rs/tower#637 Signed-off-by: katelyn martin <kate@buoyant.io>
1 parent 1c15dd0 commit 9287377

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
 

‎linkerd/stack/src/switch_ready.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
use super::NewService;
2+
use futures::future::Either;
23
use linkerd_error::Error;
34
use std::{
45
future::Future,
56
pin::Pin,
67
task::{Context, Poll},
78
};
89
use tokio::time;
9-
use tower::{spawn_ready::SpawnReady, util::Either};
10+
use tower::spawn_ready::SpawnReady;
1011
use tracing::{debug, trace};
1112

1213
/// A service which falls back to a secondary service if the primary service
@@ -100,12 +101,13 @@ where
100101
Req: 'static,
101102
A: tower::Service<Req> + Send + 'static,
102103
A::Error: Into<Error>,
103-
B: tower::Service<Req, Response = A::Response>,
104+
B: tower::Service<Req, Response = A::Response, Error = Error>,
104105
B::Error: Into<Error>,
105106
{
106107
type Response = A::Response;
107108
type Error = Error;
108-
type Future = Either<<SpawnReady<A> as tower::Service<Req>>::Future, B::Future>;
109+
type Future =
110+
Either<<SpawnReady<A> as tower::Service<Req>>::Future, <B as tower::Service<Req>>::Future>;
109111

110112
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> {
111113
loop {
@@ -165,8 +167,8 @@ where
165167
fn call(&mut self, req: Req) -> Self::Future {
166168
trace!(state = ?self.state, "SwitchReady::call");
167169
match self.state {
168-
State::Primary => Either::A(self.primary.call(req)),
169-
State::Secondary => Either::B(self.secondary.call(req)),
170+
State::Primary => Either::Left(self.primary.call(req)),
171+
State::Secondary => Either::Right(self.secondary.call(req)),
170172
State::Waiting => panic!("called before ready!"),
171173
}
172174
}

0 commit comments

Comments
 (0)
Please sign in to comment.