Skip to content

Commit

Permalink
Update chase dependency for futures 0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
fenhl committed Jan 6, 2024
1 parent 29890a1 commit 20255ea
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 23 deletions.
13 changes: 7 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 1 addition & 2 deletions crate/wurstminebot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ features = ["full"]

[dependencies.chase]
git = "https://github.com/fenhl/chase-rs"
branch = "dev-fenhl"
features = ["stream"]
branch = "wmb"

[dependencies.derive_more]
version = "0.99"
Expand Down
26 changes: 11 additions & 15 deletions crate/wurstminebot/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,8 @@ use {
sync::Arc,
time::Duration,
},
chase::{
ChaseError,
Chaser,
},
chase::Chaser,
futures::{
compat::Stream01CompatExt as _,
future::try_join_all,
pin_mut,
prelude::*,
Expand Down Expand Up @@ -43,7 +39,10 @@ use {
},
sync::RwLock,
},
tokio_stream::wrappers::LinesStream,
tokio_stream::wrappers::{
LinesStream,
ReceiverStream,
},
tokio_util::io::StreamReader,
url::Url,
wheel::{
Expand All @@ -58,7 +57,7 @@ use {

#[derive(Debug, thiserror::Error)]
pub enum Error {
#[error(transparent)] Chase(#[from] ChaseError),
#[error(transparent)] Chase(#[from] chase::Error),
#[error(transparent)] Io(#[from] io::Error),
#[error(transparent)] Json(#[from] serde_json::Error),
#[error(transparent)] Minecraft(#[from] systemd_minecraft::Error),
Expand Down Expand Up @@ -282,12 +281,9 @@ impl Line {
fn follow(http_client: reqwest::Client, world: &World) -> impl Stream<Item = Result<Line, Error>> {
let log_path = world.dir().join("logs/latest.log");
stream::once(async {
let init_lines = LinesStream::new(BufReader::new(File::open(&log_path).await?).lines()).try_fold(0, |acc, _| async move { Ok(acc + 1) }).await?;
let mut chaser = Chaser::new(log_path);
chaser.line = chase::Line(init_lines);
let (rx, _ /*handle*/) = chaser.run_stream()?; //TODO handle errors in the stream using `handle`
let stream = rx.compat()
.map_err(|()| Error::Channel)
let init_lines = LinesStream::new(BufReader::new(File::open(&log_path).await?).lines()).try_fold(0, |acc, _| future::ok(acc + 1)).await?;
let chaser = Chaser::new(log_path, chase::Line(init_lines));
let stream = ReceiverStream::new(chaser.run())
.scan(
Arc::new(RwLock::new(FollowerState {
minecraft_version: None, //TODO check log history for current Minecraft version
Expand All @@ -298,8 +294,8 @@ fn follow(http_client: reqwest::Client, world: &World) -> impl Stream<Item = Res
let state = Arc::clone(&state);
async move {
Some(match res {
Ok((line, _, _)) => Line::parse(state, &line).await,
Err(e) => Err(e),
Ok(line) => Line::parse(state, &line).await,
Err(e) => Err(e.into()),
})
}
},
Expand Down

0 comments on commit 20255ea

Please sign in to comment.