pub fn check_fn<F, E>(name: impl Into<String>, f: F) -> FnCheck<F> where
    F: Fn() -> Result<(), E> + Send + Sync + 'static,
    E: StdError + Send + Sync + 'static, 
Expand description

Wraps a synchronous function as a checkable source for health checks

If this function uses blocking I/O, consider instead using the check_future() instead and wrapping the blocking I/O in a call to tokio::task::spawn_blocking().

Example

use health::Checkable;

fn all_is_well() -> Result<(), Error> { Ok(()) }
fn everything_is_fire() -> Result<(), Error> { Err(Error {}) }

let always_ok = health::check_fn("ok", all_is_well);
assert_eq!(Ok(()), block_on(always_ok.check()));

let always_err = health::check_fn("err", everything_is_fire);
assert_eq!(Err(Error {}), block_on(always_err.check()));