Skip to content

Commit

Permalink
refactor: improve time handling and variable naming
Browse files Browse the repository at this point in the history
- Update variable names: rename *_delay to *_period for clarity
- Remove redundant code and comments in the update function
- Align interval creation with variable naming in event handler
  • Loading branch information
ShenMian committed Dec 10, 2024
1 parent 6f77d84 commit 9cd765a
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ impl App {
/// Handles the tick event of the terminal.
pub async fn update(&mut self) {
const OBJECT_UPDATE_INTERVAL: Duration = Duration::from_secs(2 * 60);

let now = Instant::now();
if now.duration_since(self.satellites_state.last_object_update) >= OBJECT_UPDATE_INTERVAL {
self.satellites_state.refresh_objects().await;
Expand Down
10 changes: 5 additions & 5 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,17 @@ pub struct EventHandler {
impl EventHandler {
/// Constructs a new instance of [`EventHandler`].
pub fn new() -> Self {
const UPDATE_RATE: f64 = 60.0;
const UPDATE_RATE: f64 = 10.0;
const RENDER_RATE: f64 = 60.0;

let update_delay = Duration::from_secs_f64(1.0 / UPDATE_RATE);
let render_delay = Duration::from_secs_f64(1.0 / RENDER_RATE);
let update_period = Duration::from_secs_f64(1.0 / UPDATE_RATE);
let render_period = Duration::from_secs_f64(1.0 / RENDER_RATE);
let (sender, receiver) = mpsc::unbounded_channel();
let _sender = sender.clone();
let handler = tokio::spawn(async move {
let mut reader = crossterm::event::EventStream::new();
let mut update_interval = tokio::time::interval(update_delay);
let mut render_interval = tokio::time::interval(render_delay);
let mut update_interval = tokio::time::interval(update_period);
let mut render_interval = tokio::time::interval(render_period);
loop {
let crossterm_event = reader.next().fuse();
tokio::select! {
Expand Down

0 comments on commit 9cd765a

Please sign in to comment.