pub enum DeduplicationResult {
New(DeduplicationToken),
InProgress,
Cached(String),
}Expand description
Outcome of a Deduplicator::check_and_register call.
Three-way classification allows callers to decide whether to do the work themselves, wait for a concurrent worker, or immediately reuse a cached result.
§Examples
use std::time::Duration;
use tokio_prompt_orchestrator::enhanced::{Deduplicator, DeduplicationResult};
let dedup = Deduplicator::new(Duration::from_secs(60));
match dedup.check_and_register("my-key").await {
DeduplicationResult::New(token) => {
let result = "computed".to_string();
dedup.complete(token, result).await;
}
DeduplicationResult::InProgress => {
// another task is already working; wait for it
let _ = dedup.wait_for_result("my-key").await;
}
DeduplicationResult::Cached(result) => {
println!("reused: {result}");
}
}Variants§
New(DeduplicationToken)
New request — should be processed by the caller.
The caller must eventually call Deduplicator::complete or
Deduplicator::fail with the returned DeduplicationToken so that
any tasks blocked in Deduplicator::wait_for_result are unblocked.
InProgress
An identical request is already being processed by another task.
The caller should call Deduplicator::wait_for_result to block until
that task completes and then reuse its result.
Cached(String)
The request was recently completed and the result is still within the cache window. The cached response string is returned directly.
Trait Implementations§
Source§impl Clone for DeduplicationResult
impl Clone for DeduplicationResult
Source§fn clone(&self) -> DeduplicationResult
fn clone(&self) -> DeduplicationResult
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for DeduplicationResult
impl !UnwindSafe for DeduplicationResult
impl Freeze for DeduplicationResult
impl Send for DeduplicationResult
impl Sync for DeduplicationResult
impl Unpin for DeduplicationResult
impl UnsafeUnpin for DeduplicationResult
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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request