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
impl ReadLedger
pub fn new() -> Self
pub fn new() -> Self
An empty ledger: nothing dispatched, nothing waiting.
pub fn dispatch(&self) -> ReadTicket
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 ⓘ
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.