|
1
|
use futures::{stream::iter, SinkExt, StreamExt}; |
|
2
|
use tokio::io::{AsyncRead, AsyncWrite}; |
|
3
|
use tokio_util::codec::{Framed, LinesCodec}; |
|
4
|
|
|
5
|
pub async fn send_commands<S>( |
|
6
|
framed: &mut Framed<S, LinesCodec>, |
|
7
|
commands: Vec<String>, |
|
8
|
) -> anyhow::Result<()> |
|
9
|
where |
|
10
|
S: AsyncRead + AsyncWrite + Unpin, |
|
11
|
{ |
|
12
|
// only need to add \r because the codec only adds \n |
|
13
|
let messages = iter(commands.into_iter().map(|x| format!("{}\r", x))); |
|
14
|
framed.send_all(&mut messages.map(Ok)).await?; |
|
15
|
Ok(()) |
|
16
|
} |