pub struct SamplingCoordinator { /* private fields */ }Expand description
Wrapper around a SamplingClient that coalesces concurrent
create_message calls into batched create_message calls
(within a configurable time window OR batch-size limit).
Construct via SamplingCoordinator::new or
SamplingCoordinator::with_settings. Drop the coordinator’s
last Arc clone to shut down the worker task.
Thread safety: cheap to clone; every clone shares the same underlying mpsc + worker task. Concurrent callers are serialised by the worker.
Implementations§
Source§impl SamplingCoordinator
impl SamplingCoordinator
Sourcepub fn new(inner: Arc<dyn SamplingClient>) -> Arc<Self>
pub fn new(inner: Arc<dyn SamplingClient>) -> Arc<Self>
Build a coordinator wrapping the supplied SamplingClient
with default settings (5s window, max-batch 10).
Sourcepub fn with_settings(
inner: Arc<dyn SamplingClient>,
window: Duration,
max_batch: usize,
) -> Arc<Self>
pub fn with_settings( inner: Arc<dyn SamplingClient>, window: Duration, max_batch: usize, ) -> Arc<Self>
Build a coordinator with explicit settings. window is the
upper bound the worker waits before flushing a non-empty
buffer; max_batch is the buffer size that triggers an
immediate flush regardless of window.
Sourcepub async fn submit(
&self,
params: CreateMessageRequestParams,
) -> Result<CreateMessageResult, SamplingError>
pub async fn submit( &self, params: CreateMessageRequestParams, ) -> Result<CreateMessageResult, SamplingError>
Coalesced equivalent of SamplingClient::create_message. The
returned future resolves when the worker has demultiplexed the
coalesced batch’s response back to this submission’s slot.
Trait Implementations§
Source§impl SamplingClient for SamplingCoordinator
impl SamplingClient for SamplingCoordinator
fn create_message<'life0, 'async_trait>(
&'life0 self,
params: CreateMessageRequestParams,
) -> Pin<Box<dyn Future<Output = Result<CreateMessageResult, SamplingError>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Auto Trait Implementations§
impl !Freeze for SamplingCoordinator
impl !RefUnwindSafe for SamplingCoordinator
impl Send for SamplingCoordinator
impl Sync for SamplingCoordinator
impl Unpin for SamplingCoordinator
impl UnsafeUnpin for SamplingCoordinator
impl !UnwindSafe for SamplingCoordinator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more