use std::sync::Arc;
use tetsy_jsonrpc_core::futures::sync::mpsc;
use tetsy_jsonrpc_pubsub::{Session, PubSubMetadata};
#[derive(Default, Clone)]
pub struct Metadata {
session: Option<Arc<Session>>,
}
impl tetsy_jsonrpc_core::Metadata for Metadata {}
impl PubSubMetadata for Metadata {
fn session(&self) -> Option<Arc<Session>> {
self.session.clone()
}
}
impl Metadata {
pub fn new(transport: mpsc::Sender<String>) -> Self {
Metadata {
session: Some(Arc::new(Session::new(transport))),
}
}
#[cfg(test)]
pub fn new_test() -> (mpsc::Receiver<String>, Self) {
let (tx, rx) = mpsc::channel(1);
(rx, Self::new(tx))
}
}
impl From<mpsc::Sender<String>> for Metadata {
fn from(sender: mpsc::Sender<String>) -> Self {
Self::new(sender)
}
}