use std::io;
use std::net::SocketAddr;
use futures::{Future, Sink, Stream};
use tokio::net::TcpStream;
use tokio_io::AsyncRead;
use error;
use resp;
pub fn connect(
addr: &SocketAddr,
) -> Box<Future<Item = ClientConnection, Error = io::Error> + Send> {
let con = TcpStream::connect(addr).map(move |socket| {
let framed = socket.framed(resp::RespCodec);
let (write_f, read_f) = framed.split();
ClientConnection {
sender: Box::new(write_f),
receiver: Box::new(read_f),
}
});
Box::new(con)
}
pub struct ClientConnection {
pub sender: Box<Sink<SinkItem = resp::RespValue, SinkError = io::Error> + Send>,
pub receiver: Box<Stream<Item = resp::RespValue, Error = error::Error> + Send>,
}