Skip to main content

EventStream

Struct EventStream 

Source
pub struct EventStream { /* private fields */ }
Expand description

In-memory event stream buffer that supports multiple consumers.

Events are stored in a bounded ring buffer. Each consumer tracks its own cursor independently. When the buffer is full, the oldest events are evicted (consumers that fall too far behind will miss events).

Implementations§

Source§

impl EventStream

Source

pub fn new(buffer_size: usize) -> Self

Create a new event stream with the given buffer capacity.

§Arguments
  • buffer_size — Maximum number of events to retain. When the buffer is full, the oldest events are evicted on push.
Source

pub fn push(&mut self, event: DecodedEvent)

Push a new event into the stream.

If the buffer is at capacity, the oldest event is evicted first.

Source

pub fn next_batch( &self, cursor: &StreamCursor, limit: usize, ) -> Result<EventBatch, IndexerError>

Fetch the next batch of events for a consumer, starting after cursor.

Returns events that come after the cursor position, up to limit events. The returned EventBatch contains a new cursor pointing to the end of the batch (use it for the next call).

If the cursor version does not match the current stream version (due to a reorg), an error is returned. The consumer should re-register or use StreamCursor::initial().

Source

pub fn register_consumer(&mut self, id: impl Into<String>)

Register a new consumer with the given ID.

The consumer starts at the initial cursor position (beginning of stream). If a consumer with this ID already exists, its cursor is reset.

Source

pub fn get_consumer_cursor(&self, id: &str) -> Option<&StreamCursor>

Get the current cursor for a registered consumer.

Returns None if the consumer is not registered.

Source

pub fn update_consumer_cursor(&mut self, id: &str, cursor: StreamCursor)

Update a consumer’s cursor (e.g., after processing a batch).

Source

pub fn invalidate_after(&mut self, block_number: u64)

Invalidate all events at or above block_number (reorg handling).

Removes affected events from the buffer and increments the stream version, which invalidates all outstanding cursors.

Source

pub fn len(&self) -> usize

Returns the current number of events in the buffer.

Source

pub fn is_empty(&self) -> bool

Returns true if the buffer is empty.

Source

pub fn version(&self) -> u64

Returns the current stream version.

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more