pub struct CoarseClock { /* private fields */ }Expand description
A wall clock the paid-delivery hot path can read with a single relaxed atomic
load instead of a SystemTime::now() syscall (issue #1792 item 4).
Refreshed on a timer by Self::spawn_refresher; reads fall back to a live
clock until (and if ever) a refresher runs. See the module docs.
Implementations§
Source§impl CoarseClock
impl CoarseClock
Sourcepub const fn new() -> Self
pub const fn new() -> Self
A clock with no refresher: every read is live until Self::spawn_refresher
starts stamping the cell.
Sourcepub fn unix_millis(&self) -> u64
pub fn unix_millis(&self) -> u64
Unix milliseconds — the refreshed value, or a live reading while the cell
still holds its 0 sentinel.
Sourcepub fn unix_seconds(&self) -> u64
pub fn unix_seconds(&self) -> u64
Unix seconds, floored from Self::unix_millis. Matches
SystemTime::now().duration_since(UNIX_EPOCH).as_secs() for the same
instant, so it is a drop-in for the expiry gate’s prior
payment_settlement::unix_now().
Sourcepub fn spawn_refresher(clock: &Arc<Self>, interval: Duration)
pub fn spawn_refresher(clock: &Arc<Self>, interval: Duration)
Spawn a background task that refreshes clock every interval until the
last strong reference to it is dropped.
The task holds only a Weak, so it is
self-terminating and needs no StopHandle
wiring: once every ClientHandler
holding the clock is gone (runtime shutdown), the next upgrade() fails
and the loop exits — at most one interval later. It also owns no queue
and awaits no sender, so the detached-task hazard StopHandle exists to
prevent does not apply here.
The first tick fires immediately (a fresh tokio::time::interval is
ready at once), so the cell leaves its 0 sentinel as soon as the task is
scheduled; reads before then are live, not wrong.
Trait Implementations§
Source§impl Debug for CoarseClock
impl Debug for CoarseClock
Auto Trait Implementations§
impl !Freeze for CoarseClock
impl RefUnwindSafe for CoarseClock
impl Send for CoarseClock
impl Sync for CoarseClock
impl Unpin for CoarseClock
impl UnsafeUnpin for CoarseClock
impl UnwindSafe for CoarseClock
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> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
fn with_context(self, otel_cx: Context) -> WithContext<Self> ⓘ
Source§fn with_current_context(self) -> WithContext<Self> ⓘ
fn with_current_context(self) -> WithContext<Self> ⓘ
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 moreSource§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>
T in a tonic::Request