Skip to content

Commit

Permalink
chore: remove useless code
Browse files Browse the repository at this point in the history
  • Loading branch information
0x5459 authored and seanmonstar committed Nov 6, 2023
1 parent bf4ea94 commit a4c20a3
Showing 1 changed file with 0 additions and 69 deletions.
69 changes: 0 additions & 69 deletions tower/src/balance/p2c/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,13 @@ use crate::ready_cache::{error::Failed, ReadyCache};
use crate::util::rng::{sample_floyd2, HasherRng, Rng};
use futures_core::ready;
use futures_util::future::{self, TryFutureExt};
use pin_project_lite::pin_project;
use std::hash::Hash;
use std::marker::PhantomData;
use std::{
fmt,
future::Future,
pin::Pin,
task::{Context, Poll},
};
use tokio::sync::oneshot;
use tower_service::Service;
use tracing::{debug, trace};

Expand Down Expand Up @@ -58,25 +55,6 @@ where
}
}

pin_project! {
/// A Future that becomes satisfied when an `S`-typed service is ready.
///
/// May fail due to cancelation, i.e., if [`Discover`] removes the service from the service set.
struct UnreadyService<K, S, Req> {
key: Option<K>,
#[pin]
cancel: oneshot::Receiver<()>,
service: Option<S>,

_req: PhantomData<Req>,
}
}

enum Error<E> {
Inner(E),
Canceled,
}

impl<D, Req> Balance<D, Req>
where
D: Discover,
Expand Down Expand Up @@ -279,50 +257,3 @@ where
.map_err(Into::into)
}
}

impl<K, S: Service<Req>, Req> Future for UnreadyService<K, S, Req> {
type Output = Result<(K, S), (K, Error<S::Error>)>;

fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
let this = self.project();

if let Poll::Ready(Ok(())) = this.cancel.poll(cx) {
let key = this.key.take().expect("polled after ready");
return Poll::Ready(Err((key, Error::Canceled)));
}

let res = ready!(this
.service
.as_mut()
.expect("poll after ready")
.poll_ready(cx));

let key = this.key.take().expect("polled after ready");
let svc = this.service.take().expect("polled after ready");

match res {
Ok(()) => Poll::Ready(Ok((key, svc))),
Err(e) => Poll::Ready(Err((key, Error::Inner(e)))),
}
}
}

impl<K, S, Req> fmt::Debug for UnreadyService<K, S, Req>
where
K: fmt::Debug,
S: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let Self {
key,
cancel,
service,
_req,
} = self;
f.debug_struct("UnreadyService")
.field("key", key)
.field("cancel", cancel)
.field("service", service)
.finish()
}
}

0 comments on commit a4c20a3

Please sign in to comment.