failsafe icon indicating copy to clipboard operation
failsafe copied to clipboard

Consider allowing custom failure when timeout exceeded

Open jhalterman opened this issue 5 years ago • 5 comments

Ex:

Timeout<Object> timeout = Timeout.of(Duration.ofSeconds(10))
  .withFailure(() -> new ConnectionTimeoutException());
Failsafe.with(timeout).run(this::connect);

as opposed to using a Fallback:

Timeout<Object> timeout = Timeout.of(Duration.ofSeconds(10));
Fallback<Object> fallback = Fallback.ofException(e -> new ConnectionTimeoutException())
  .handle(TimeoutException.class);
Failsafe.with(fallback, timeout).run(this::connect);

jhalterman avatar Jan 28 '20 22:01 jhalterman

Registering a Fallback that acts upon a TimeoutExceededExcecption doesn't work?

whiskeysierra avatar Jan 29 '20 07:01 whiskeysierra

Yep that would be the current approach. I'm wondering if it's worth doing something more convenient though.

jhalterman avatar Jan 29 '20 16:01 jhalterman

It's based on existing features and works exactly like any other fallback. I like it.

On Wed, 29 Jan 2020, 17:01 Jonathan Halterman, [email protected] wrote:

Yep that would be the current approach. I'm wondering if it's worth doing something more convenient though.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jhalterman/failsafe/issues/225?email_source=notifications&email_token=AADI7HOBAFJQNH35UXODRY3RAGR6PA5CNFSM4KM2WAAKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEKHXRNQ#issuecomment-579827894, or unsubscribe https://github.com/notifications/unsubscribe-auth/AADI7HOKKC7YF4ODBOARQETRAGR6PANCNFSM4KM2WAAA .

whiskeysierra avatar Jan 29 '20 20:01 whiskeysierra

Updated the OP to give some clearer code level examples of what this means.

jhalterman avatar Jan 29 '20 21:01 jhalterman

Allowing something like this could also enhance RetryPolicy #202 ?

paulius-p avatar Feb 04 '20 14:02 paulius-p