pub struct SingleFlight { /* private fields */ }Expand description
Guard for a single-flight fill, returned by
CacheKit::single_flight.
Holds the per-key in-process lock for its whole lifetime, and the
distributed fill lock (if one was acquired) until Self::release.
Dropping without release is safe: the in-process lock frees immediately
and a distributed lock expires server-side after its timeout.
Implementations§
Source§impl SingleFlight
impl SingleFlight
Sourcepub async fn wait_for_fill(&mut self) -> bool
pub async fn wait_for_fill(&mut self) -> bool
true while another worker may still be filling this key — re-check
the cache after every true before computing yourself:
- Leader: immediately
false(compute, don’t re-read your own miss). - Queued behind a local holder:
trueonce, for the re-check, thenfalse. If the holder found the distributed lock contested and let go without a fill, a missed re-check first contests that lock and then behaves as a leader or a contested flight. - Contested cross-process: sleeps one poll interval per call,
trueuntil the lock timeout (5 s), measured from this flight’s lock attempt, has passed. A hung re-check is not cut short here;#[cachekit]bounds its own.
Sourcepub async fn release(self)
pub async fn release(self)
Release the flight. Best-effort: frees the distributed fill lock (if
held) so other processes stop waiting early. A failed release is
traced (feature tracing) and otherwise ignored: the lock expires
server-side regardless. Leaves the stand-down note as it is (see the
FlightMap docs), since a caller may release after an error, with no fill.
Auto Trait Implementations§
impl !RefUnwindSafe for SingleFlight
impl !UnwindSafe for SingleFlight
impl Freeze for SingleFlight
impl Send for SingleFlight
impl Sync for SingleFlight
impl Unpin for SingleFlight
impl UnsafeUnpin for SingleFlight
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