Skip to main content

with_timeout

Function with_timeout 

Source
pub fn with_timeout<F, T>(timeout: Duration, work: F) -> Result<T, ExecError>
where F: FnOnce() -> Result<T, ExecError> + Send + 'static, T: Send + 'static,
Expand description

Run work on a worker thread; return its result or Err(ExecError::Timeout) if it doesn’t finish within timeout.

work must be 'static + Send so it can move to the worker. Pass owned data in (clone if needed) — borrowing across the boundary would force 'static lifetimes everywhere upstream.