Struct OptimisticQueue
pub struct OptimisticQueue { /* private fields */ }Expand description
A local optimistic replica plus the confirmed baseline it can rebuild from.
The transport must treat ActionId as an idempotency key. Accepted
actions are incorporated into the confirmed baseline by
Self::acknowledge, so authoritative snapshots passed to
Self::merge_authoritative must not also echo still-pending actions.
Buffer such a snapshot until its client action acknowledgements have
settled, or send unrelated host changes as a separate Automerge delta.
Implementations§
§impl OptimisticQueue
impl OptimisticQueue
pub fn new(live: &mut AutoCommit) -> OptimisticQueue
pub fn new(live: &mut AutoCommit) -> OptimisticQueue
Begin at live’s current committed state. Pending open Automerge ops
are committed by get_heads so the baseline is unambiguous.
pub fn submit<A>(
&mut self,
live: &mut AutoCommit,
action: &A,
encoded: EncodedAction,
) -> Result<ActionEnvelope, OptimisticError>where
A: Action,
pub fn submit<A>(
&mut self,
live: &mut AutoCommit,
action: &A,
encoded: EncodedAction,
) -> Result<ActionEnvelope, OptimisticError>where
A: Action,
Apply now, return the envelope to send, and remember it until the host accepts or rejects it.
§Errors
Returns OptimisticError::LiveDiverged for out-of-session writes,
or an action/Automerge error when local application fails.
pub fn submit_by<A>(
&mut self,
live: &mut AutoCommit,
action: &A,
encoded: EncodedAction,
actor: Option<&[u8]>,
) -> Result<ActionEnvelope, OptimisticError>where
A: Action,
pub fn submit_by<A>(
&mut self,
live: &mut AutoCommit,
action: &A,
encoded: EncodedAction,
actor: Option<&[u8]>,
) -> Result<ActionEnvelope, OptimisticError>where
A: Action,
pub fn acknowledge(
&mut self,
id: ActionId,
registry: &ActionRegistry,
) -> Result<Acknowledgement, OptimisticError>
pub fn acknowledge( &mut self, id: ActionId, registry: &ActionRegistry, ) -> Result<Acknowledgement, OptimisticError>
Mark one reply accepted. Out-of-order replies remain marked until all predecessors are accepted; the confirmed replica then advances through the contiguous prefix in order.
§Errors
Returns a decode/application error or
OptimisticError::ConfirmationBaseMismatch without advancing the
confirmed baseline.
pub fn reject(
&mut self,
live: &mut AutoCommit,
id: ActionId,
registry: &ActionRegistry,
) -> Result<RebaseBatch, OptimisticError>
pub fn reject( &mut self, live: &mut AutoCommit, id: ActionId, registry: &ActionRegistry, ) -> Result<RebaseBatch, OptimisticError>
Remove a refused action, roll the live replica back to confirmed state,
and replay every survivor with fresh ids/base heads. The caller sends
the returned replacements and cancels/ignores superseded ids.
§Errors
Returns a decode or action-application error. The queue and live document remain unchanged on failure.
Merge a host replica into the confirmed baseline, then rebase pending work on top. With no pending work the live replica simply becomes the merged confirmed state. See the type-level transport contract before merging a snapshot that contains this client’s accepted actions.
§Errors
Returns an Automerge merge error or a pending-action replay error. The queue and live document remain unchanged on failure.
pub fn reconnect_batch(&self) -> Vec<ActionEnvelope>
pub fn reconnect_batch(&self) -> Vec<ActionEnvelope>
Envelopes to resend after reconnect. No local replay occurs: their
optimistic effects are already present in live.
pub fn pending_len(&self) -> usize
pub fn is_settled(&self) -> bool
pub fn confirmed(&self) -> &AutoCommit
pub fn confirmed(&self) -> &AutoCommit
Read-only confirmed state, useful for connection/status UI and tests.
pub fn confirmed_heads(&self) -> Vec<ChangeHash>
pub fn confirmed_heads(&self) -> Vec<ChangeHash>
The causal heads of the host-confirmed baseline.
pub fn is_superseded(&self, id: ActionId) -> bool
Auto Trait Implementations§
impl Freeze for OptimisticQueue
impl RefUnwindSafe for OptimisticQueue
impl Send for OptimisticQueue
impl Sync for OptimisticQueue
impl Unpin for OptimisticQueue
impl UnsafeUnpin for OptimisticQueue
impl UnwindSafe for OptimisticQueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.§impl<T> DowncastSync for T
impl<T> DowncastSync for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more