From c7894e9ee7dd821f2832062383d6cb92c32a2c60 Mon Sep 17 00:00:00 2001 From: Santtu Lakkala Date: Tue, 1 Oct 2024 13:38:02 +0300 Subject: [PATCH] Revert client API changes Signed-off-by: Santtu Lakkala --- client/src/client.rs | 9 ++------- src/bin/givc-cli.rs | 21 +++++---------------- 2 files changed, 7 insertions(+), 23 deletions(-) diff --git a/client/src/client.rs b/client/src/client.rs index fe54944..d096329 100644 --- a/client/src/client.rs +++ b/client/src/client.rs @@ -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; @@ -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, - - pub task: Pin>>, } #[derive(Debug)] @@ -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) { @@ -203,12 +199,11 @@ impl AdminClient { break; } } - }; + }); let result = WatchResult { initial: list, channel: rx, - task: Box::pin(task), }; Ok(result) } diff --git a/src/bin/givc-cli.rs b/src/bin/givc-cli.rs index 7835fe2..7e9d728 100644 --- a/src/bin/givc-cli.rs +++ b/src/bin/givc-cli.rs @@ -1,4 +1,3 @@ -use anyhow::anyhow; use clap::{Parser, Subcommand}; use givc::endpoint::TlsConfig; use givc::types::*; @@ -194,27 +193,17 @@ async fn main() -> std::result::Result<(), Box> { 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)?; + } } };