Skip to content

Commit 67dfad8

Browse files
committed
util: Add ServiceExt::buffered
1 parent 505e7e6 commit 67dfad8

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

tower/src/util/mod.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@ use std::future::Future;
4848

4949
use crate::layer::util::Identity;
5050

51+
#[cfg(feature = "buffer")]
52+
use crate::buffer::Buffer;
53+
5154
pub mod error {
5255
//! Error types
5356
@@ -944,6 +947,20 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
944947
MapFuture::new(self, f)
945948
}
946949

950+
/// Returns a buffered version of this service.
951+
///
952+
/// See [`Buffer::new()`] for the details.
953+
#[cfg(feature = "buffer")]
954+
fn buffered(self, bound: usize) -> Buffer<Request, Self::Future>
955+
where
956+
Self: Send + Sized + 'static,
957+
Self::Future: Send,
958+
Self::Error: Into<crate::BoxError> + Send + Sync,
959+
Request: Send + Sized + 'static,
960+
{
961+
Buffer::new(self, bound)
962+
}
963+
947964
/// Convert the service into a [`Service`] + [`Send`] trait object.
948965
///
949966
/// See [`BoxService`] for more details.

0 commit comments

Comments
 (0)