Skip to content

Commit

Permalink
Fix buffered events not getting dispatched
Browse files Browse the repository at this point in the history
  • Loading branch information
Osspial committed Nov 19, 2018
1 parent 2c18b80 commit 54ce6a2
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/platform_impl/windows/event_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,26 @@ impl<T> ELRShared<T> {
if let Ok(mut runner_ref) = self.runner.try_borrow_mut() {
if let Some(ref mut runner) = *runner_ref {
runner.process_event(event);

// Dispatch any events that were buffered during the call to `process_event`.
loop {
// We do this instead of using a `while let` loop because if we use a `while let`
// loop the reference returned `borrow_mut()` doesn't get dropped until the end
// of the loop's body and attempts to add events to the event buffer while in
// `process_event` will fail.
let buffered_event_opt = self.buffer.borrow_mut().pop_front();
match buffered_event_opt {
Some(event) => runner.process_event(event),
None => break
}
}

return;
}
}

// If the runner is already borrowed, we're in the middle of an event loop invocation. Add
// the event to a buffer to be processed later.
self.buffer.borrow_mut().push_back(event)
}
}
Expand Down

0 comments on commit 54ce6a2

Please sign in to comment.