Last active
May 4, 2020 11:45
-
-
Save gterzian/1ec0cc2c451597f8f6565d2805413c20 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
recv(from_processor_receiver) -> msg => { | |
let _ = work_sender.send(SourceMsg::TickAdjusted); | |
match msg { | |
Ok(RegulateSourceMsg::SlowDown) => { | |
current_ticker_duration = match current_ticker_duration { | |
Some(tick) => { | |
if tick > 100 { | |
Some(100) | |
} else { | |
Some(tick * 2) | |
} | |
}, | |
None => continue, | |
}; | |
ticker = tick(Duration::from_millis(current_ticker_duration.unwrap())); | |
}, | |
Ok(RegulateSourceMsg::SpeedUp) => { | |
current_ticker_duration = match current_ticker_duration { | |
Some(tick) if tick > 2 => Some(tick / 2), | |
Some(tick) => Some(tick), | |
// If we're in "stopped" mode, re-start slowly. | |
None => Some(100), | |
}; | |
ticker = tick(Duration::from_millis(current_ticker_duration.unwrap())); | |
}, | |
Ok(RegulateSourceMsg::Stop) => { | |
current_ticker_duration = None; | |
ticker = never(); | |
}, | |
_ => panic!("Error receiving a RegulateSourceMsg."), | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment