Hi, I have an algorithm that takes a potentially really long time to execute. I want to call that function with a set timeout and if that timeout expires, just return a default. I read about async await
with tokio
, but that requires me to make both the caller and the receiver async
. If possible I want to avoid that or hide it away, so that the function can be called from a sync
context. Is there a way to do that and if so, where can I look?
Basically I have:
fn might_take_too_long(params) -> SomeReturn
and I want fn might_take_too_long_with_timeout(params, timeout: Duration) -> Option<SomeReturn>
that calls the former function but returns None
if it exceeds the timeout.