Skip to main content

ReadLedger

Struct ReadLedger 

pub struct ReadLedger { /* private fields */ }
Expand description

The read-only round trips a transport has dispatched and the endpoint has not yet answered.

A cheap handle: clones share one ledger, and one ledger is one ordering domain. A transport holds one, calls dispatch for every read-only request before round_trip returns, and moves the ReadTicket to whatever observes the answer — a spawned task on the host, a promise’s settlement callback on wasm32. Its reads_settled is then settled.

Reads are ordered by generation, not counted. A waiter waits only for the reads dispatched before it was created, so a steady stream of later reads cannot hold an append back indefinitely.

use core::pin::pin;
use core::task::{Context, Poll, Waker};
use happenstance_neon::transport::ReadLedger;

let ledger = ReadLedger::new();
let in_flight = ledger.dispatch();
let mut settled = pin!(ledger.settled());
let mut cx = Context::from_waker(Waker::noop());

assert_eq!(settled.as_mut().poll(&mut cx), Poll::Pending);
in_flight.settle(); // the endpoint answered
assert_eq!(settled.as_mut().poll(&mut cx), Poll::Ready(()));

Implementations§

§

impl ReadLedger

pub fn new() -> Self

An empty ledger: nothing dispatched, nothing waiting.

pub fn dispatch(&self) -> ReadTicket

Records one read as dispatched and returns the proof that it has not settled.

Call it before round_trip returns, and move the ticket to whatever observes the answer. Dropping the ticket — or calling ReadTicket::settle — settles the read.

pub fn settled(&self) -> ReadsSettled ⓘ

A future that resolves once every read dispatched before this call has settled.

The horizon is fixed here, at the call, not at the first poll: a read dispatched between the two does not extend the wait.

Trait Implementations§

§

impl Clone for ReadLedger

§

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 Debug for ReadLedger

§

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

Formats the value using the given formatter. Read more
§

impl Default for ReadLedger

§

fn default() -> Self

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

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