pub fn with_runtime<R>(
ctx: RuntimeContext,
f: impl FnOnce() -> Result<R>,
) -> Result<R>Expand description
Runs f with an explicitly supplied runtime installed for the duration of
the closure.
Any previously configured default runtime is restored afterwards, even when
f returns an error.
ยงExamples
use tenferro_internal_runtime::{with_default_runtime, with_runtime, RuntimeContext};
use tenferro_prims::CpuContext;
let name = with_runtime(RuntimeContext::Cpu(CpuContext::new(1)), || {
with_default_runtime(|ctx| Ok(ctx.name()))
})
.unwrap();
assert_eq!(name, "cpu");