pub fn split_stream<S>(cfg: &WsConfig, stream: S) -> (WebSocketStream<S>, EncodeStream) {
    let (tx, rx) = channel::channel();

    let codec = cfg.codec.unwrap_or_else(Codec::new);

    let (timer, interval) = match cfg.heartbeat {
        Some(dur) => (Some(sleep(dur)), dur),
        None => (None, Duration::from_secs(1)),
    };

    let queue = WebSocketLocalQueue::new();

    (
        WebSocketStream {
            decode: DecodeStream {
                stream,
                timer,
                hb: HeartBeat::new(interval, cfg.timeout, cfg.server_send_heartbeat),
                queue: queue.clone(),
                codec,
                read_buf: BytesMut::new(),
            },
            tx: WebSocketSender(tx),
        },
        EncodeStream {
            queue,
            rx,
            codec,
            write_buf: BytesMut::new(),
        },
    )
}
/// split stream into decode/encode streams and a sender that can send item to encode stream.
split stream into decode/encode streams and a sender that can send item to encode stream.
split stream into decode / encode streams and a sender that can send item to encode stream .
pub fn split_stream<S>(cfg: &WsConfig, stream: S) -> (WebSocketStream<S>, EncodeStream) {
    let (tx, rx) = channel::channel();
    let codec = cfg.codec.unwrap_or_else(Codec::new);
    let (timer, interval) = match cfg.heartbeat {
        Some(dur) => (Some(sleep(dur)), dur),
        None => (None, Duration::from_secs(1)),
    };
    let queue = WebSocketLocalQueue::new();
    (
        WebSocketStream {
            decode: DecodeStream {
                stream,
                timer,
                hb: HeartBeat::new(interval, cfg.timeout, cfg.server_send_heartbeat),
                queue: queue.clone(),
                codec,
                read_buf: BytesMut::new(),
            },
            tx: WebSocketSender(tx),
        },
        EncodeStream {
            queue,
            rx,
            codec,
            write_buf: BytesMut::new(),
        },
    )
}
pub fn split_stream < S > ( cfg : & WsConfig , stream : S ) -> ( WebSocketStream < S > , EncodeStream ) { let ( tx , rx ) = channel :: channel ( ) ; let codec = cfg . codec . unwrap_or_else ( Codec :: new ) ; let ( timer , interval ) = match cfg . heartbeat { Some ( dur ) => ( Some ( sleep ( dur ) ) , dur ) , None => ( None , Duration :: from_secs ( 1 ) ) , } ; let queue = WebSocketLocalQueue :: new ( ) ; ( WebSocketStream { decode : DecodeStream { stream , timer , hb : HeartBeat :: new ( interval , cfg . timeout , cfg . server_send_heartbeat ) , queue : queue . clone ( ) , codec , read_buf : BytesMut :: new ( ) , } , tx : WebSocketSender ( tx ) , } , EncodeStream { queue , rx , codec , write_buf : BytesMut :: new ( ) , } , ) }
split stream into decode/encode streams and a sender that can send item to encode stream.
split stream into decode / encode streams and a sender that can send item to encode stream .
cfg
&WsConfig
stream
S