Execution Context

Failsafe can provide an ExecutionContext containing execution related information such as the number of execution attempts, start and elapsed times, and the last result or exception:

Failsafe.with(retryPolicy).run(ctx -> {
  log.debug("Connection attempt #{}", ctx.getAttemptCount());

This is useful for retrying executions that depend on results from a previous attempt:

int result = Failsafe.with(retryPolicy).get(ctx -> ctx.getLastResult(0) + 1);