pub struct Lease { /* private fields */ }Expand description
A time-bounded obligation that keeps remote work alive.
Leases are the distributed equivalent of structured ownership. A lease holder must periodically renew the lease; if the lease expires without renewal, the remote side assumes the holder is gone and cleans up.
§Obligation Integration
A Lease wraps an ObligationId with ObligationKind::Lease. This
means the owning region cannot close until the lease is resolved (released
or expired). This is how remote tasks participate in region quiescence.
§Lifecycle
create() → Active ──renew()──► Active (extended)
│
├─ release() ──► Released (obligation committed)
│
└─ expires ────► Expired (obligation aborted)§Example
use asupersync::remote::{Lease, LeaseId};
use std::time::Duration;
let lease = Lease::new(obligation_id, region, task, Duration::from_secs(30), now);
assert!(lease.is_active(now));
// Renew before expiry
lease.renew(Duration::from_secs(30), later);
// Release when done
lease.release(even_later);Implementations§
Source§impl Lease
impl Lease
Sourcepub fn new(
obligation_id: ObligationId,
region: RegionId,
holder: TaskId,
duration: Duration,
now: Time,
) -> Self
pub fn new( obligation_id: ObligationId, region: RegionId, holder: TaskId, duration: Duration, now: Time, ) -> Self
Creates a new active lease.
The obligation_id should be created via
RuntimeState::create_obligation(ObligationKind::Lease, ...).
Sourcepub fn obligation_id(&self) -> ObligationId
pub fn obligation_id(&self) -> ObligationId
Returns the underlying obligation ID.
Sourcepub fn expires_at(&self) -> Time
pub fn expires_at(&self) -> Time
Returns the absolute expiry time.
Sourcepub fn initial_duration(&self) -> Duration
pub fn initial_duration(&self) -> Duration
Returns the initial lease duration.
Sourcepub fn state(&self) -> LeaseState
pub fn state(&self) -> LeaseState
Returns the current lease state.
Sourcepub fn renewal_count(&self) -> u32
pub fn renewal_count(&self) -> u32
Returns the number of times this lease has been renewed.
Sourcepub fn is_active(&self, now: Time) -> bool
pub fn is_active(&self, now: Time) -> bool
Returns true if the lease is active (not expired, not released).
Sourcepub fn is_expired(&self, now: Time) -> bool
pub fn is_expired(&self, now: Time) -> bool
Returns true if the lease has expired (time exceeded without renewal).
Sourcepub fn is_released(&self) -> bool
pub fn is_released(&self) -> bool
Returns true if the lease has been explicitly released.
Sourcepub fn remaining(&self, now: Time) -> Duration
pub fn remaining(&self, now: Time) -> Duration
Returns the remaining time before expiry, or zero if expired.
Sourcepub fn renew(&mut self, duration: Duration, now: Time) -> Result<(), LeaseError>
pub fn renew(&mut self, duration: Duration, now: Time) -> Result<(), LeaseError>
Renews the lease by extending the expiry from now.
§Errors
Returns LeaseError::Expired if the lease has already expired.
Returns LeaseError::Released if the lease was already released.
Sourcepub fn release(&mut self, now: Time) -> Result<(), LeaseError>
pub fn release(&mut self, now: Time) -> Result<(), LeaseError>
Explicitly releases the lease.
This resolves the underlying obligation as committed (clean release).
§Errors
Returns LeaseError::Released if already released.
Returns LeaseError::Expired if already expired.
Sourcepub fn mark_expired(&mut self) -> Result<(), LeaseError>
pub fn mark_expired(&mut self) -> Result<(), LeaseError>
Marks the lease as expired.
Called by the runtime when it detects that the lease has passed its
expiry time without renewal. The underlying obligation should be
aborted with ObligationAbortReason::Cancel.
§Errors
Returns LeaseError::Released if already released.