upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/client.rs21
1 files changed, 17 insertions, 4 deletions
diff --git a/src/client.rs b/src/client.rs
index 9bc171a..2b0c960 100644
--- a/src/client.rs
+++ b/src/client.rs
@@ -10,12 +10,12 @@
10// which is currently in nightly. alternatively we can use nightly as it looks 10// which is currently in nightly. alternatively we can use nightly as it looks
11// certain that the implementation is going to make it to stable but we don't 11// certain that the implementation is going to make it to stable but we don't
12// want to inadvertlty use other features of nightly that might be removed. 12// want to inadvertlty use other features of nightly that might be removed.
13use std::time::Duration; 13use std::{fmt::Write, time::Duration};
14 14
15use anyhow::{Context, Result}; 15use anyhow::{Context, Result};
16use async_trait::async_trait; 16use async_trait::async_trait;
17use futures::stream::{self, StreamExt}; 17use futures::stream::{self, StreamExt};
18use indicatif::{MultiProgress, ProgressBar, ProgressStyle}; 18use indicatif::{MultiProgress, ProgressBar, ProgressState, ProgressStyle};
19#[cfg(test)] 19#[cfg(test)]
20use mockall::*; 20use mockall::*;
21use nostr::Event; 21use nostr::Event;
@@ -143,7 +143,18 @@ impl Connect for Client {
143 } 143 }
144 144
145 let m = MultiProgress::new(); 145 let m = MultiProgress::new();
146 let pb_style = ProgressStyle::with_template(" {spinner} {prefix} {msg}")?; 146 let pb_style = ProgressStyle::with_template(" {spinner} {prefix} {msg} {timeout_in}")?
147 .with_key("timeout_in", |state: &ProgressState, w: &mut dyn Write| {
148 if state.elapsed().as_secs() > 3 {
149 write!(
150 w,
151 "timeout in {:.1}s",
152 GET_EVENTS_TIMEOUT - state.elapsed().as_secs()
153 )
154 .unwrap();
155 }
156 });
157
147 let pb_after_style = |succeed| { 158 let pb_after_style = |succeed| {
148 ProgressStyle::with_template( 159 ProgressStyle::with_template(
149 format!( 160 format!(
@@ -228,6 +239,8 @@ impl Connect for Client {
228 } 239 }
229} 240}
230 241
242static GET_EVENTS_TIMEOUT: u64 = 10;
243
231async fn get_events_of( 244async fn get_events_of(
232 relay: &nostr_sdk::Relay, 245 relay: &nostr_sdk::Relay,
233 filters: Vec<nostr::Filter>, 246 filters: Vec<nostr::Filter>,
@@ -244,7 +257,7 @@ async fn get_events_of(
244 .get_events_of( 257 .get_events_of(
245 filters, 258 filters,
246 // 20 is nostr_sdk default 259 // 20 is nostr_sdk default
247 std::time::Duration::from_secs(10), 260 std::time::Duration::from_secs(GET_EVENTS_TIMEOUT),
248 nostr_sdk::FilterOptions::ExitOnEOSE, 261 nostr_sdk::FilterOptions::ExitOnEOSE,
249 ) 262 )
250 .await?; 263 .await?;