commit f0781fb98860ea92d92f76e9f7c094748d303cd4
parent 31014c2120f7345bbb91c72cb0542f025b76da38
Author: William Casarin <jb55@jb55.com>
Date: Wed, 22 Oct 2025 09:38:08 -0700
timeout: standardize timeouts
working on a plane so this is needed
Signed-off-by: William Casarin <jb55@jb55.com>
Diffstat:
3 files changed, 6 insertions(+), 9 deletions(-)
diff --git a/.envrc b/.envrc
@@ -1,2 +1,3 @@
use nix
export TODO_FILE=TODO
+export TIMEOUT_MS=15000
diff --git a/src/main.rs b/src/main.rs
@@ -30,6 +30,7 @@ mod html;
mod nip19;
mod pfp;
mod render;
+mod timeout;
use crate::secp256k1::XOnlyPublicKey;
@@ -192,12 +193,6 @@ async fn serve(
}
}
-fn get_env_timeout() -> Duration {
- let timeout_env = std::env::var("TIMEOUT_MS").unwrap_or("2000".to_string());
- let timeout_ms: u64 = timeout_env.parse().unwrap_or(2000);
- Duration::from_millis(timeout_ms)
-}
-
fn get_gradient() -> egui::ColorImage {
use egui::{Color32, ColorImage};
//use egui::pos2;
@@ -251,7 +246,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
let cfg = Config::new();
let ndb = Ndb::new(".", &cfg).expect("ndb failed to open");
let keys = Keys::generate();
- let timeout = get_env_timeout();
+ let timeout = timeout::get_env_timeout();
let img_cache = Arc::new(LruCache::new(std::num::NonZeroUsize::new(64).unwrap()));
let default_pfp = egui::ImageData::Color(Arc::new(get_default_pfp()));
let background = egui::ImageData::Color(Arc::new(get_gradient()));
diff --git a/src/render.rs b/src/render.rs
@@ -1,3 +1,4 @@
+use crate::timeout;
use crate::{abbrev::abbrev_str, error::Result, fonts, nip19, Error, Notecrumbs};
use egui::epaint::Shadow;
use egui::{
@@ -316,13 +317,13 @@ pub async fn find_note(
}
client
- .connect_with_timeout(std::time::Duration::from_millis(800))
+ .connect_with_timeout(timeout::get_env_timeout())
.await;
debug!("finding note(s) with filters: {:?}", filters);
let mut streamed_events = client
- .stream_events(filters, Some(std::time::Duration::from_millis(2000)))
+ .stream_events(filters, Some(timeout::get_env_timeout()))
.await?;
let mut num_loops = 0;