use std::pin::Pin;
use std::task::{Context, Poll};
use zmq::{Error, SocketType};
use crate::socket::{MessageBuf, Reciever, SocketBuilder, ZmqSocket};
use crate::Stream;
pub fn pull(endpoint: &str) -> Result<SocketBuilder<'_, Pull>, zmq::Error> {
let socket = zmq::Context::new().socket(SocketType::PULL)?;
Ok(SocketBuilder::new(socket, endpoint))
}
pub struct Pull(Reciever);
impl Pull {
pub fn as_raw_socket(&self) -> &zmq::Socket {
&self.0.socket.get_ref().0
}
}
impl From<zmq::Socket> for Pull {
fn from(socket: zmq::Socket) -> Self {
Self(Reciever {
socket: ZmqSocket::from(socket),
})
}
}
impl Stream for Pull {
type Item = Result<MessageBuf, Error>;
fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>> {
Pin::new(&mut self.get_mut().0).poll_next(cx)
}
}