Skip to main content

Waiting

Enum Waiting 

pub enum Waiting {
    Nothing,
    Unknown,
    Events(NonZeroU64),
}
Expand description

What the far side still holds past the token a pull returned, as Pulled::waiting reports it.

Three cases, because a runner faces three: it knows there is nothing more, it knows how much more there is, or it was not told. Spelled as an enum rather than an Option<u64>, which cannot say “not told” without a sentinel, and rather than a flag beside an optional count, which can say “nothing more, and here are three”.

The count is a NonZeroU64, so “nothing” has one spelling: Events(0) cannot be written, and a runner matching on Nothing misses no second form of it. Its decoder refuses a zero from the wire for the same reason. Not #[non_exhaustive]: the three cases are the whole space, and a runner should get the compiler’s exhaustiveness check when it matches.

§On the wire

Externally tagged, in snake case: "nothing", "unknown", or {"events":3}. In postcard the variant index is the declaration order — Nothing 0, Unknown 1, Events 2 — so the variants are never reordered.

§Examples

A runner that believes Nothing stops after the pull that says it, rather than spending one more round trip on a pull that comes back empty — the round trip SY-15 says is the expensive one:

use happenstance_core::{Event, EventId, RecordedAt, SequencePosition, StoreId};
use happenstance_sync::{
    EventGroup, MemorySyncPeer, ReplicatedEvent, SyncPeer, Waiting,
};

let tablet = StoreId::from_bytes([1; 16]);
let hub = MemorySyncPeer::new(StoreId::from_bytes([2; 16]));
hub.seed(EventGroup::new(None, vec![ReplicatedEvent::new(
    EventId::new(tablet, SequencePosition::FIRST),
    RecordedAt::from_millis(1_700_000_000_000),
    Event::new("ReadingTaken", &b"{\"celsius\":4}"[..])?,
)]))?;

let mut from = None;
let mut pulls = 0;
loop {
    let pulled = hub.pull(from.as_ref()).await?;
    pulls += 1;
    // ... ingest `pulled.batch` here, then keep the token ...
    let caught_up = pulled.waiting == Waiting::Nothing || pulled.batch.groups.is_empty();
    from = Some(pulled.resume);
    if caught_up {
        break;
    }
}
assert_eq!(pulls, 1, "told nothing is waiting, the runner skips the empty pull");

Variants§

§

Nothing

Nothing: no group lies past this answer’s token, so the next pull from it returns an empty batch unless the far side takes a write in between (SY-37). A peer stalled behind a group it cannot carry says Events, never this.

§

Unknown

The peer did not say. The caller pulls again to find out, which is what every pull cost before this field existed.

§

Events(NonZeroU64)

This many events lay past the token when the far side answered.

Advisory: more may have arrived since, and a group too large for the next pull’s budget can hold that pull empty while this is non-zero.

Implementations§

§

impl Waiting

pub const fn counted(remaining: u64) -> Self

Nothing for zero, Events otherwise: the count an adapter’s count(*), or its limit-plus-one probe, produced.

Trait Implementations§

§

impl Clone for Waiting

§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Copy for Waiting

§

impl Debug for Waiting

§

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

Formats the value using the given formatter. Read more
§

impl Default for Waiting

§

fn default() -> Self

Returns the “default value” for a type. Read more
§

impl<'de> Deserialize<'de> for Waiting

§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
§

impl Eq for Waiting

§

impl Hash for Waiting

§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for Waiting

§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl Serialize for Waiting

§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
§

impl StructuralPartialEq for Waiting

Auto Trait Implementations§

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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.