Skip to content

Commit

Permalink
[feat]: Made io reading methods async
Browse files Browse the repository at this point in the history
  • Loading branch information
batconjurer committed Jul 26, 2023
1 parent c5a2ce2 commit cfb57ab
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
2 changes: 2 additions & 0 deletions apps/src/lib/cli/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ impl CliClient for HttpClient {
}

pub struct CliIo;

#[async_trait::async_trait(?Send)]
impl Io for CliIo {}

pub struct CliApi<IO: Io = CliIo>(PhantomData<IO>);
2 changes: 1 addition & 1 deletion shared/src/ledger/eth_bridge/bridge_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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:?}"
Expand Down
6 changes: 4 additions & 2 deletions shared/src/types/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str>) {
Expand Down Expand Up @@ -40,11 +42,11 @@ pub trait Io {
eprintln!("{}", output.as_ref());
}

fn read() -> std::io::Result<String> {
async fn read() -> std::io::Result<String> {
read_aux(std::io::stdin().lock())
}

fn prompt(question: impl AsRef<str>) -> String {
async fn prompt(question: impl AsRef<str>) -> String {
prompt_aux(
std::io::stdin().lock(),
std::io::stdout(),
Expand Down

0 comments on commit cfb57ab

Please sign in to comment.