From cfb57ab19234c53dcca18d8164fccaa81c5e3551 Mon Sep 17 00:00:00 2001 From: satan Date: Wed, 26 Jul 2023 13:26:36 +0200 Subject: [PATCH] [feat]: Made io reading methods async --- apps/src/lib/cli/api.rs | 2 ++ shared/src/ledger/eth_bridge/bridge_pool.rs | 2 +- shared/src/types/io.rs | 6 ++++-- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/src/lib/cli/api.rs b/apps/src/lib/cli/api.rs index c53f277e29..2cf609f18e 100644 --- a/apps/src/lib/cli/api.rs +++ b/apps/src/lib/cli/api.rs @@ -28,6 +28,8 @@ impl CliClient for HttpClient { } pub struct CliIo; + +#[async_trait::async_trait(?Send)] impl Io for CliIo {} pub struct CliApi(PhantomData); diff --git a/shared/src/ledger/eth_bridge/bridge_pool.rs b/shared/src/ledger/eth_bridge/bridge_pool.rs index 4891468e58..235941eb6a 100644 --- a/shared/src/ledger/eth_bridge/bridge_pool.rs +++ b/shared/src/ledger/eth_bridge/bridge_pool.rs @@ -221,7 +221,7 @@ where display!(IO, "\nDo you wish to proceed? (y/n): "); IO::flush(); loop { - let resp = IO::read().try_halt(|e| { + let resp = IO::read().await.try_halt(|e| { display_line!( IO, "Encountered error reading from STDIN: {e:?}" diff --git a/shared/src/types/io.rs b/shared/src/types/io.rs index 72904ac114..80eeb2eb69 100644 --- a/shared/src/types/io.rs +++ b/shared/src/types/io.rs @@ -5,8 +5,10 @@ /// Rust native I/O handling. pub struct DefaultIo; +#[async_trait::async_trait(?Send)] impl Io for DefaultIo {} +#[async_trait::async_trait(?Send)] #[allow(missing_docs)] pub trait Io { fn print(output: impl AsRef) { @@ -40,11 +42,11 @@ pub trait Io { eprintln!("{}", output.as_ref()); } - fn read() -> std::io::Result { + async fn read() -> std::io::Result { read_aux(std::io::stdin().lock()) } - fn prompt(question: impl AsRef) -> String { + async fn prompt(question: impl AsRef) -> String { prompt_aux( std::io::stdin().lock(), std::io::stdout(),