pub struct Hold { /* private fields */ }Expand description
A deadline before which no request on a throttle may proceed.
A throttle’s buckets model the quota a venue publishes; a hold is what
the server actually just said. They disagree more often than the tables
suggest — Cloudflare’s error code: 1015 is an IP-scoped block with its
own window, and it answers 429 no matter how many tokens the buckets still
hold. So a 429 holds every request sharing the throttle, not just the one
that saw it.
A hold only ever extends: several concurrent requests typically see the
same 429 within a few milliseconds of each other, and taking the most
recent value would let whichever response carried the smallest delay
release all of them early. wait re-reads the deadline
after waking, so a hold extended mid-wait is honoured in full.
A hold keeps time on a Runtime: it reads its
deadline off the runtime’s clock and its waits sleep on the runtime.
unbounded and with_ceiling
take the target’s default runtime, unbounded_on and
with_ceiling_on the one given. Every layer that
waits and shares the hold keeps time on the hold’s runtime, so one throttle
never mixes two clocks.
A clone shares the deadline. Every layer of one throttle holds a clone of
one Hold, so replacing or resizing a layer keeps it.
Implementations§
Source§impl Hold
impl Hold
Sourcepub fn unbounded() -> Self
pub fn unbounded() -> Self
A hold with no ceiling, on the target’s default runtime: every
extend is taken as asked.
Sourcepub fn unbounded_on(runtime: Arc<dyn Runtime>) -> Self
pub fn unbounded_on(runtime: Arc<dyn Runtime>) -> Self
As unbounded, keeping time on runtime.
Sourcepub fn with_ceiling(ceiling: Duration) -> Self
pub fn with_ceiling(ceiling: Duration) -> Self
A hold that clamps every extend to ceiling, so a
server asking for longer holds for ceiling, on the target’s default
runtime.
Sourcepub fn with_ceiling_on(ceiling: Duration, runtime: Arc<dyn Runtime>) -> Self
pub fn with_ceiling_on(ceiling: Duration, runtime: Arc<dyn Runtime>) -> Self
As with_ceiling, keeping time on runtime.
Sourcepub fn runtime(&self) -> &Arc<dyn Runtime> ⓘ
pub fn runtime(&self) -> &Arc<dyn Runtime> ⓘ
The runtime this hold keeps time on, which every layer sharing the hold keeps time on too.