Function retry

Retry executing a given delegate at most X times and wait between the retries. As soon as the delegate is executed successfully, the function immediately returns.

Nullable!(ReturnType!dg) retry(alias dg, T) (
  T waiter,
  long max_retries,
  Duration duration,
  string error_msg = "Operation timed out: "
);

Parameters

NameDescription
dg the delegate we want to execute X times
waiter object implementing the wait() primitive
max_retries maximum number of times the delegate is executed
duration the time between retrying to execute the delegate
error_msg optional error message

Returns

returns Nullable() in case the delegate cannot be executed after X retries or when the delegate returns false, otherwise it returns the original return value of the delegate wrapped into a Nullable object