@@ -356,19 +356,6 @@ impl<T: 'static> EventLoop<T> {
356356
357357 /// Wait for one message and dispatch it, optionally with a timeout
358358 fn wait_and_dispatch_message ( & mut self , timeout : Option < Duration > ) {
359- let start = Instant :: now ( ) ;
360-
361- let runner = & self . window_target . p . runner_shared ;
362-
363- let control_flow_timeout = match runner. control_flow ( ) {
364- ControlFlow :: Wait => None ,
365- ControlFlow :: Poll => Some ( Duration :: ZERO ) ,
366- ControlFlow :: WaitUntil ( wait_deadline) => {
367- Some ( wait_deadline. saturating_duration_since ( start) )
368- }
369- } ;
370- let timeout = min_timeout ( control_flow_timeout, timeout) ;
371-
372359 fn get_msg_with_timeout ( msg : & mut MSG , timeout : Option < Duration > ) -> PumpStatus {
373360 unsafe {
374361 // A timeout of None means wait indefinitely (so we don't need to call SetTimer)
@@ -404,6 +391,8 @@ impl<T: 'static> EventLoop<T> {
404391 }
405392 }
406393
394+ let runner = & self . window_target . p . runner_shared ;
395+
407396 // We aim to be consistent with the MacOS backend which has a RunLoop
408397 // observer that will dispatch AboutToWait when about to wait for
409398 // events, and NewEvents after the RunLoop wakes up.
@@ -415,6 +404,16 @@ impl<T: 'static> EventLoop<T> {
415404 //
416405 runner. prepare_wait ( ) ;
417406
407+ let control_flow_timeout = match runner. control_flow ( ) {
408+ ControlFlow :: Wait => None ,
409+ ControlFlow :: Poll => Some ( Duration :: ZERO ) ,
410+ ControlFlow :: WaitUntil ( wait_deadline) => {
411+ let start = Instant :: now ( ) ;
412+ Some ( wait_deadline. saturating_duration_since ( start) )
413+ }
414+ } ;
415+ let timeout = min_timeout ( control_flow_timeout, timeout) ;
416+
418417 // # Safety
419418 // The Windows API has no documented requirement for bitwise
420419 // initializing a `MSG` struct (it can be uninitialized memory for the C
0 commit comments