use std::sync::{Arc, Mutex};
use super::ChannelEnd;
#[derive(Clone)]
pub struct ServerWebSocket {
end: Arc<Mutex<Option<ChannelEnd>>>,
}
impl ServerWebSocket {
pub(crate) fn new(end: ChannelEnd) -> Self {
Self {
end: Arc::new(Mutex::new(Some(end))),
}
}
pub fn take(&self) -> Option<ChannelEnd> {
self.end
.lock()
.unwrap_or_else(|error| error.into_inner())
.take()
}
}
impl std::fmt::Debug for ServerWebSocket {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("ServerWebSocket")
.finish_non_exhaustive()
}
}