Skip to content

Commit

Permalink
Ignore tick send error
Browse files Browse the repository at this point in the history
  • Loading branch information
joshka committed Aug 27, 2024
1 parent ddb5fe3 commit c6d2b6a
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 4 additions & 1 deletion simple-generated/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ impl EventSource {
/// thread. It sends a tick event at a regular interval. The tick rate is specified by the
/// `tick_rate` parameter. If an error occurs, it sends an error event to the main thread and then
/// stops running.
///
/// Errors sending an event are ignored as this generally indicates that the main thread has exited
/// and is no longer listening for events.
fn event_thread(sender: mpsc::Sender<Event>, tick_rate: Duration) {
let mut last_tick: Option<Instant> = None;
loop {
if last_tick
.map(|tick| tick.elapsed() >= tick_rate)
.unwrap_or(true)
{
sender.send(Event::Tick).expect("failed to send tick event");
let _ = sender.send(Event::Tick);
last_tick = Some(Instant::now());
}

Expand Down
5 changes: 4 additions & 1 deletion simple/src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,17 @@ impl EventSource {
/// thread. It sends a tick event at a regular interval. The tick rate is specified by the
/// `tick_rate` parameter. If an error occurs, it sends an error event to the main thread and then
/// stops running.
///
/// Errors sending an event are ignored as this generally indicates that the main thread has exited
/// and is no longer listening for events.
fn event_thread(sender: mpsc::Sender<Event>, tick_rate: Duration) {
let mut last_tick: Option<Instant> = None;
loop {
if last_tick
.map(|tick| tick.elapsed() >= tick_rate)
.unwrap_or(true)
{
sender.send(Event::Tick).expect("failed to send tick event");
let _ = sender.send(Event::Tick);
last_tick = Some(Instant::now());
}

Expand Down

0 comments on commit c6d2b6a

Please sign in to comment.