Function crius::command_with_fallback
source · pub fn command_with_fallback<I, O, E>(
config: Config,
function: CommandFn<I, O, E>,
fallback: FallbackFn<O, E>
) -> Result<Command<I, O, E>, CriusError>where
E: From<CriusError>,
Expand description
Use this function to construct a circuit breaker with a fallback function:
Example:
// Define a simple circuit breaker command:
let mut cmd = command_with_fallback(
Config::default(),
// Same function as in the `command`-example
double_if_lt_ten,
// Define a fallback:
|_err| 4, // It's always four.
).unwrap();
// and run it with an example input:
let result = cmd.run(11);
assert_eq!(Ok(4), result)