pub struct Monitor {
event_emitter: Arc<EventEmitter<MonitorTopic>>,
config: Arc<Config>,
}
Expand description
Responsible for network and system monitoring.
It use event emitter to notify the registerd listeners about new events.
§Example
use std::sync::Arc;
use smol::Executor;
use karyon_p2p::{
Config, Backend, PeerID, keypair::{KeyPair, KeyPairType}, monitor::ConnectionEvent,
};
async {
// Create a new Executor
let ex = Arc::new(Executor::new());
let key_pair = KeyPair::generate(&KeyPairType::Ed25519);
let backend = Backend::new(&key_pair, Config::default(), ex.into());
// Create a new Subscription
let monitor = backend.monitor();
let listener = monitor.register::<ConnectionEvent>().await;
let new_event = listener.recv().await;
};
Fields§
§event_emitter: Arc<EventEmitter<MonitorTopic>>
§config: Arc<Config>
Implementations§
Source§impl Monitor
impl Monitor
Sourcepub(crate) async fn notify<E: ToEventStruct>(&self, event: E)
pub(crate) async fn notify<E: ToEventStruct>(&self, event: E)
Sends a new monitor event to subscribers.
Sourcepub async fn register<E>(&self) -> EventListener<MonitorTopic, E>
pub async fn register<E>(&self) -> EventListener<MonitorTopic, E>
Registers a new event listener for the provided topic.
Auto Trait Implementations§
impl Freeze for Monitor
impl !RefUnwindSafe for Monitor
impl Send for Monitor
impl Sync for Monitor
impl Unpin for Monitor
impl !UnwindSafe for Monitor
Blanket Implementations§
§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
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