Skip to content

Commit

Permalink
Merge pull request #108 from mobusoperandi/repl_event_error
Browse files Browse the repository at this point in the history
refactor: variant ReplEvent::Error
  • Loading branch information
mightyiam authored Jun 8, 2024
2 parents 4fb81e5 + bc52819 commit 7696f4f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
8 changes: 2 additions & 6 deletions src/app/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ impl State {
ReplEvent::Query(id, query, result) => self.repl_event_query(id, query, result),
ReplEvent::Kill(id) => self.repl_event_kill(id),
ReplEvent::Read(id, result) => self.repl_event_read(id, result),
ReplEvent::Error(error) => Err(error.into()),
}
}

Expand Down Expand Up @@ -121,14 +122,9 @@ impl State {
Ok(Vec::new())
}

fn repl_event_read(
&mut self,
id: ExampleId,
result: std::io::Result<u8>,
) -> anyhow::Result<Vec<OutputEvent>> {
fn repl_event_read(&mut self, id: ExampleId, ch: u8) -> anyhow::Result<Vec<OutputEvent>> {
let session_live = self.examples.get_mut_repl(&id)?;
let session_live = session_live.state.live_mut()?;
let ch = result?;

let output = match &mut session_live.expecting {
ReplSessionExpecting::Nothing => anyhow::bail!("not expecting, got {:?}", ch as char),
Expand Down
10 changes: 4 additions & 6 deletions src/repl/driver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ pub(crate) enum ReplEvent {
Spawn(pty_process::Result<ExampleId>),
Query(ExampleId, ReplQuery, anyhow::Result<()>),
Kill(anyhow::Result<ExampleId>),
Read(ExampleId, std::io::Result<u8>),
Read(ExampleId, u8),
Error(std::io::Error),
}

pub(crate) struct ReplDriver {
Expand Down Expand Up @@ -102,15 +103,12 @@ impl ReplDriver {
match byte {
Ok(byte) => {
self.sender
.send(ReplEvent::Read(id.clone(), Ok(byte)))
.send(ReplEvent::Read(id.clone(), byte))
.await
.unwrap();
}
Err(error) => {
self.sender
.send(ReplEvent::Read(id.clone(), Err(error)))
.await
.unwrap();
self.sender.send(ReplEvent::Error(error)).await.unwrap();
}
}
}
Expand Down

0 comments on commit 7696f4f

Please sign in to comment.