I am trying to read input lines from the console. I am using the async_std crate for reading the lines.
The stdin.readline
is called at multiple places.
Is there a way to cancel or flush the previous instance of stdin.read_line
, before calling trying to read stdin.read_line
again?
rust code:
let create_spawn = async move {
let stdin = io::stdin();
let mut input_line = String::new();
let r = stdin.read_line(&mut input_line);
let l = r.await?;
log::debug!("received the input line: {}", input_line);
Ok::<(), anyhow::Error>(())
};
let c1 = tokio::spawn(create_spawn);
delay();
// <---cancel the previous instance of `stdin.read_line` --->
let c2 = tokio::spawn(create_spawn);