use tokio::sync::mpsc;
use unb_core::Envelope;
use unb_runtime::Pipe;
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,
..
}
));
}
}