//! [`Future`] types //! //! [`Future`]: std::future::Future use futures_core::ready; use pin_project_lite::pin_project; use std::{ future::Future, pin::Pin, task::{Context, Poll}, }; use tokio::sync::OwnedSemaphorePermit; pin_project! { /// Future for the [`ConcurrencyLimit`] service. /// /// [`ConcurrencyLimit`]: crate::limit::ConcurrencyLimit #[derive(Debug)] pub struct ResponseFuture { #[pin] inner: T, // Keep this around so that it is dropped when the future completes _permit: OwnedSemaphorePermit, } } impl ResponseFuture { pub(crate) fn new(inner: T, _permit: OwnedSemaphorePermit) -> ResponseFuture { ResponseFuture { inner, _permit } } } impl Future for ResponseFuture where F: Future>, { type Output = Result; fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll { Poll::Ready(ready!(self.project().inner.poll(cx))) } }