unb-client 2.0.3

unb outbound client: WebSocket + in-process dialing (native) over the sans-IO core; wasm-safe
Documentation
use tokio::sync::mpsc;
use unb_core::Envelope;

use unb_runtime::Pipe;

/// Cross-wired in-process local pipes: frames pass as `Envelope` values, never
/// serialized. The first side is the initiator (dialer), the second the acceptor.
pub fn pair() -> (Pipe, Pipe) {
    let (a_to_b_tx, a_to_b_rx) = mpsc::channel::<Envelope>(64);
    let (b_to_a_tx, b_to_a_rx) = mpsc::channel::<Envelope>(64);
    (
        Pipe::Local {
            rx: b_to_a_rx,
            tx: a_to_b_tx,
            initiator: true,
        },
        Pipe::Local {
            rx: a_to_b_rx,
            tx: b_to_a_tx,
            initiator: false,
        },
    )
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn pair_has_opposite_roles() {
        let (dialer, listener) = pair();
        assert!(matches!(
            dialer,
            Pipe::Local {
                initiator: true,
                ..
            }
        ));
        assert!(matches!(
            listener,
            Pipe::Local {
                initiator: false,
                ..
            }
        ));
    }
}