Finite state machines in rust; bendns fork to add types.
Diffstat (limited to 'rust_fsm/examples/circuit_breaker.rs')
-rw-r--r--rust_fsm/examples/circuit_breaker.rs7
1 files changed, 4 insertions, 3 deletions
diff --git a/rust_fsm/examples/circuit_breaker.rs b/rust_fsm/examples/circuit_breaker.rs
index fa31883..b2814d3 100644
--- a/rust_fsm/examples/circuit_breaker.rs
+++ b/rust_fsm/examples/circuit_breaker.rs
@@ -3,6 +3,7 @@
/// https://martinfowler.com/bliki/CircuitBreaker.html
use rust_fsm::*;
use std::sync::{Arc, Mutex};
+use std::time::Duration;
#[derive(Debug)]
enum CircuitBreakerInput {
@@ -76,7 +77,7 @@ fn main() {
// Set up a timer
let machine_wait = machine.clone();
std::thread::spawn(move || {
- std::thread::sleep_ms(5000);
+ std::thread::sleep(Duration::new(5, 0));
let mut lock = machine_wait.lock().unwrap();
let res = lock.consume_anyway(&CircuitBreakerInput::TimerTriggered);
assert_eq!(res, None);
@@ -86,7 +87,7 @@ fn main() {
// Try to pass a request when the circuit breaker is still open
let machine_try = machine.clone();
std::thread::spawn(move || {
- std::thread::sleep_ms(1000);
+ std::thread::sleep(Duration::new(1, 0));
let mut lock = machine_try.lock().unwrap();
let res = lock.consume_anyway(&CircuitBreakerInput::Successful);
assert_eq!(res, None);
@@ -94,7 +95,7 @@ fn main() {
});
// Test if the circit breaker was actually closed
- std::thread::sleep_ms(7000);
+ std::thread::sleep(Duration::new(7, 0));
{
let mut lock = machine.lock().unwrap();
let res = lock.consume_anyway(&CircuitBreakerInput::Successful);