pub struct Singleflight<T> { /* private fields */ }Expand description
Coalesce concurrent loads for the same key.
Implementations§
Source§impl<T> Singleflight<T>
impl<T> Singleflight<T>
pub fn new(fail_ttl: Duration) -> Self
pub fn get_ready(&self, key: &LoadKey) -> Option<Arc<T>>
pub fn contains_ready(&self, key: &LoadKey) -> bool
pub fn invalidate(&self, key: &LoadKey)
pub fn clear(&self)
pub fn ready_count(&self) -> usize
Sourcepub fn finish_load_published(&self, key: &LoadKey)
pub fn finish_load_published(&self, key: &LoadKey)
Complete a coalesced load without retaining a permanent Ready slot (JOE-1646). The caller must have already published the value into the authoritative registry. Waiters wake, see no Loading slot, and re-query the registry.
Sourcepub fn finish_load_failed(&self, key: &LoadKey, message: String)
pub fn finish_load_failed(&self, key: &LoadKey, message: String)
Mark a failed coalesced load.
Sourcepub fn begin_or_wait(&self, key: &LoadKey) -> BeginLoad
pub fn begin_or_wait(&self, key: &LoadKey) -> BeginLoad
Begin a coalesced load for registry-owned residency (JOE-1646).
BeginLoad::Leader: this caller must load, insert into the registry, then callSelf::finish_load_publishedorSelf::finish_load_failed.BeginLoad::WaitDone: a concurrent load finished; re-check the registry.BeginLoad::Failed: recent failure still in TTL window.
Sourcepub fn begin_or_wait_guard(
&self,
key: LoadKey,
) -> Result<Option<LeaderGuard<'_, T>>, String>
pub fn begin_or_wait_guard( &self, key: LoadKey, ) -> Result<Option<LeaderGuard<'_, T>>, String>
Acquire leadership for key and return a panic-safe LeaderGuard.
Ok(None) means another load finished — re-check the registry.
Err is a cached failure message still within TTL.
Source§impl<T: Send + Sync + 'static> Singleflight<T>
impl<T: Send + Sync + 'static> Singleflight<T>
Trait Implementations§
Auto Trait Implementations§
impl<T> !Freeze for Singleflight<T>
impl<T> RefUnwindSafe for Singleflight<T>
impl<T> Send for Singleflight<T>
impl<T> Sync for Singleflight<T>
impl<T> Unpin for Singleflight<T>
impl<T> UnsafeUnpin for Singleflight<T>
impl<T> UnwindSafe for Singleflight<T>
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
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>
Converts
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>
Converts
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