Skip to content

Instantly share code, notes, and snippets.

@gterzian
Last active May 4, 2020 11:45
Show Gist options
  • Save gterzian/1ec0cc2c451597f8f6565d2805413c20 to your computer and use it in GitHub Desktop.
Save gterzian/1ec0cc2c451597f8f6565d2805413c20 to your computer and use it in GitHub Desktop.
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