pub struct ChainEventBus { /* private fields */ }Expand description
A broadcast-based event bus for chain state changes.
Multiple subscribers can listen for events without blocking the
publisher. The bus is cheap to clone (it shares the underlying
channel via Arc).
Implementations§
Source§impl ChainEventBus
impl ChainEventBus
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create a new event bus with a custom capacity.
Sourcepub fn subscribe(&self) -> Receiver<ChainEvent>
pub fn subscribe(&self) -> Receiver<ChainEvent>
Subscribe to chain events.
Returns a broadcast::Receiver that will receive all events
emitted after this call. If the receiver falls behind, it will
get a RecvError::Lagged with the number of missed events.
Sourcepub fn emit(&self, event: ChainEvent) -> usize
pub fn emit(&self, event: ChainEvent) -> usize
Emit a chain event to all subscribers.
Returns the number of active subscribers that received the event. Returns 0 if there are no subscribers (this is not an error).
Sourcepub fn subscriber_count(&self) -> usize
pub fn subscriber_count(&self) -> usize
Get the current number of active subscribers.
Sourcepub fn notify_block_connected(
&self,
hash: BlockHash,
height: u32,
num_txs: usize,
) -> usize
pub fn notify_block_connected( &self, hash: BlockHash, height: u32, num_txs: usize, ) -> usize
Convenience: emit a BlockConnected event.
Sourcepub fn notify_block_disconnected(&self, hash: BlockHash, height: u32) -> usize
pub fn notify_block_disconnected(&self, hash: BlockHash, height: u32) -> usize
Convenience: emit a BlockDisconnected event.
Sourcepub fn notify_tx_added(&self, txid: Txid, vsize: u64, fee: i64) -> usize
pub fn notify_tx_added(&self, txid: Txid, vsize: u64, fee: i64) -> usize
Convenience: emit a TransactionAddedToMempool event.
Sourcepub fn notify_tx_removed(
&self,
txid: Txid,
reason: MempoolRemovalReason,
) -> usize
pub fn notify_tx_removed( &self, txid: Txid, reason: MempoolRemovalReason, ) -> usize
Convenience: emit a TransactionRemovedFromMempool event.
Trait Implementations§
Source§impl Clone for ChainEventBus
impl Clone for ChainEventBus
Source§fn clone(&self) -> ChainEventBus
fn clone(&self) -> ChainEventBus
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more