pub struct GraphSubscriber { /* private fields */ }Expand description
Async helper that pairs a SharedGraph with a broadcast receiver
to yield batches of GraphDiff entries whenever the graph changes.
§Example
ⓘ
let subscriber = GraphSubscriber::new(graph.clone());
loop {
match subscriber.next_batch().await {
Ok(diffs) => { /* process diffs */ }
Err(gap) => { /* full resync needed */ }
}
}Implementations§
Source§impl GraphSubscriber
impl GraphSubscriber
Sourcepub fn new(graph: SharedGraph) -> Self
pub fn new(graph: SharedGraph) -> Self
Create a new subscriber starting from the graph’s current version.
Sourcepub fn from_version(graph: SharedGraph, version: u64) -> Self
pub fn from_version(graph: SharedGraph, version: u64) -> Self
Create a subscriber starting from a specific version.
Useful for resuming after a reconnect.
Sourcepub async fn next_batch(&mut self) -> Result<Vec<GraphDiff>, ChangelogGap>
pub async fn next_batch(&mut self) -> Result<Vec<GraphDiff>, ChangelogGap>
Wait for the next batch of changes and return them.
Blocks (async) until at least one write occurs, then returns all
diffs since the last consumed version. Returns Err(ChangelogGap)
if the subscriber has fallen too far behind.
Auto Trait Implementations§
impl Freeze for GraphSubscriber
impl !RefUnwindSafe for GraphSubscriber
impl Send for GraphSubscriber
impl Sync for GraphSubscriber
impl Unpin for GraphSubscriber
impl UnsafeUnpin for GraphSubscriber
impl !UnwindSafe for GraphSubscriber
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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