failsafe-lib / failsafe

Fault tolerance and resilience patterns for the JVM
https://failsafe.dev
Apache License 2.0
4.17k stars 296 forks source link

Add a typed parameter for the failure in FailurePolicy.handleIf #288

Open jhalterman opened 3 years ago

jhalterman commented 3 years ago

Small improvement, though I'm not sure if it's worth doing. Thoughts?

--

This is meant to make it slightly (maybe? arguably?) easier to write FailurePolicy.handleIf statements that are specifically typed. Ex:

Before

policy.handleIf((Object result, HttpException failure) -> failure.isServerError())

After

policy.<HttpException>handleIf((result, failure) -> failure.isServerError());

This could open the door for ClassCastExceptions, but those are ignored by FailurePoilicy: https://github.com/failsafe-lib/failsafe/blob/master/src/main/java/net/jodah/failsafe/FailurePolicy.java#L160-L162

Tembrel commented 3 years ago

After code is missing method name, should be:

policy.<HttpException>handleIf((result, failure) -> failure.isServerError());
jhalterman commented 3 years ago

🤦 thanks, edited.