Skip to main content

Lease

Struct Lease 

Source
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

Source

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, ...).

Source

pub fn obligation_id(&self) -> ObligationId

Returns the underlying obligation ID.

Source

pub fn region(&self) -> RegionId

Returns the owning region.

Source

pub fn holder(&self) -> TaskId

Returns the holding task.

Source

pub fn expires_at(&self) -> Time

Returns the absolute expiry time.

Source

pub fn initial_duration(&self) -> Duration

Returns the initial lease duration.

Source

pub fn state(&self) -> LeaseState

Returns the current lease state.

Source

pub fn renewal_count(&self) -> u32

Returns the number of times this lease has been renewed.

Source

pub fn is_active(&self, now: Time) -> bool

Returns true if the lease is active (not expired, not released).

Source

pub fn is_expired(&self, now: Time) -> bool

Returns true if the lease has expired (time exceeded without renewal).

Source

pub fn is_released(&self) -> bool

Returns true if the lease has been explicitly released.

Source

pub fn remaining(&self, now: Time) -> Duration

Returns the remaining time before expiry, or zero if expired.

Source

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.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Debug for Lease

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl Freeze for Lease

§

impl RefUnwindSafe for Lease

§

impl Send for Lease

§

impl Sync for Lease

§

impl Unpin for Lease

§

impl UnsafeUnpin for Lease

§

impl UnwindSafe for Lease

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, _span: NoopSpan) -> Self

Instruments this future with a span (no-op when disabled).
Source§

fn in_current_span(self) -> Self

Instruments this future with the current span (no-op when disabled).
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V