Skip to content

Commit

Permalink
Revert client API changes
Browse files Browse the repository at this point in the history
Signed-off-by: Santtu Lakkala <[email protected]>
  • Loading branch information
slakkala committed Oct 1, 2024
1 parent 99f7d0b commit c7894e9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 23 deletions.
9 changes: 2 additions & 7 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ use anyhow::bail;
use async_channel::Receiver;
use givc_common::pb;
pub use givc_common::query::{Event, QueryResult};
use std::future::Future;
use std::pin::Pin;
use tokio_stream::StreamExt;
use tonic::transport::Channel;
use tracing::debug;
Expand All @@ -20,8 +18,6 @@ pub struct WatchResult {
// Design defence: we use `async-channel` here, as it could be used with both
// tokio's and glib's eventloop, and recommended by gtk4-rs developers:
pub channel: Receiver<Event>,

pub task: Pin<Box<dyn Future<Output = ()>>>,
}

#[derive(Debug)]
Expand Down Expand Up @@ -184,7 +180,7 @@ impl AdminClient {
None => bail!("Protocol error, status field missing"),
};

let task = async move {
tokio::spawn(async move {
loop {
if let Ok(Some(event)) = watch.try_next().await {
let event = match Event::try_from(event) {
Expand All @@ -203,12 +199,11 @@ impl AdminClient {
break;
}
}
};
});

let result = WatchResult {
initial: list,
channel: rx,
task: Box::pin(task),
};
Ok(result)
}
Expand Down
21 changes: 5 additions & 16 deletions src/bin/givc-cli.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use anyhow::anyhow;
use clap::{Parser, Subcommand};
use givc::endpoint::TlsConfig;
use givc::types::*;
Expand Down Expand Up @@ -194,27 +193,17 @@ async fn main() -> std::result::Result<(), Box<dyn std::error::Error>> {
limit,
initial: dump_initial,
} => {
let WatchResult {
initial,
channel,
mut task,
} = admin.watch().await?;
let WatchResult { initial, channel } = admin.watch().await?;
let mut limit = limit.map(|l| 0..l);

if dump_initial {
dump(initial, as_json)?
}

tokio::select! {
res = async move {
// Change to Option::is_none_or() with rust >1.82
while !limit.as_mut().is_some_and(|l| l.next().is_none()) {
dump(channel.recv().await?, as_json)?;
}
Ok(())
} => res,
_ = task.as_mut() => Err(anyhow!("Watch task stopped unexpectedly"))
}?
// Change to Option::is_none_or() with rust >1.82
while !limit.as_mut().is_some_and(|l| l.next().is_none()) {
dump(channel.recv().await?, as_json)?;
}
}
};

Expand Down

0 comments on commit c7894e9

Please sign in to comment.