use super::*;
pub(in crate::tui::runtime) fn spawn_top_positions_refresh(
rpc_url: String,
configs: std::collections::HashMap<String, SplineConfig>,
marks: std::collections::HashMap<String, f64>,
gti_cache: GtiHandle,
gti_refresh: Arc<tokio::sync::Notify>,
tx: UnboundedSender<Vec<TopPositionEntry>>,
) -> tokio::task::JoinHandle<()> {
tokio::spawn(async move {
let fut = async {
let cache_guard = gti_cache.read().await;
fetch_top_positions(&rpc_url, &configs, &marks, cache_guard.as_ref()).await
};
match tokio::time::timeout(TOP_POSITIONS_TIMEOUT, fut).await {
Ok(Ok(entries)) => {
let had_miss = entries.iter().any(|e| e.trader.is_none());
if had_miss {
gti_refresh.notify_one();
}
let _ = tx.send(entries);
}
Ok(Err(e)) => {
warn!(error = %e, "top positions refresh failed");
}
Err(_) => {
warn!("top positions refresh timed out");
}
}
})
}