use crate::{ToPayload, event::LogEvent};
use tokio::sync::mpsc;
#[derive(Debug)]
pub struct LogHandle<T: ToPayload> {
pub(crate) sender: mpsc::Sender<Option<LogEvent<T>>>,
}
impl<T: ToPayload> LogHandle<T> {
pub async fn send(
&self,
event: Option<LogEvent<T>>,
) -> Result<(), mpsc::error::SendError<Option<LogEvent<T>>>> {
self.sender.send(event).await
}
pub fn try_send(
&self,
event: Option<LogEvent<T>>,
) -> Result<(), mpsc::error::TrySendError<Option<LogEvent<T>>>> {
self.sender.try_send(event)
}
}
impl<T: ToPayload> Drop for LogHandle<T> {
fn drop(&mut self) {
self.sender.try_send(None).unwrap();
}
}