failsafe-lib / failsafe

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

FailsafeCall micro refactoring, plus World-Wide Nr.1 duplicated utility method for OkHttp #351

Open magicprinc opened 2 years ago

magicprinc commented 2 years ago

As you can see here: https://github.com/magicprinc/failsafe/commit/c517e3ef01aec35cd6b6aaa23779873f8e89ffab

FailsafeCall micro refactoring: 1) AtomicBoolean fields are final 2) lambda expression instead of code block

2) World-Wide Nr.1 duplicated utility method for OkHttp `/* [OkHttp Callback to JDK CompletableFuture]
Helps eliminate dozens of utility classes World-wide with exactly this same method.
Can be the first small step towards FailSafe.
Returns normal JDK {@link CompletableFuture} without FailSafe policies.
/

public static CompletableFuture asPromise (okhttp3.Call call)`

All around the World, people write this method again and again. I have done it too. We really need "The Chosen One". I recommend you to be this one :-)

If you like it, I will send it as PR.

Tembrel commented 2 years ago
  1. AtomicBoolean fields are final

OK

  1. lambda expression instead of code block

Aren't those braces ignored, anyway? It's just a single expression. (The indenting of the modified code is off, btw.)

All around the World, people write this method again and again. I have done it too. We really need "The Chosen One". I recommend you to be this one :-)

Does this utility belong in FailsafeCall.java? If included at all, wouldn't it be better as a single static method in a utility class?

magicprinc commented 2 years ago

Aren't those braces ignored, anyway? It's just a single expression. (The indenting of the modified code is off, btw.)

IntelliJ IDEA's work :-)

As I know, the resulting byte code is the same.

Does this utility belong in FailsafeCall.java? If included at all, wouldn't it be better as a single static method in a utility class?

To be honest, not 100%... but I really want to drop such "one method utility class" in my codebase. And I don't like to add new dependencies. Failsafe have managed after long testing, etc.

🙏

If you do some research in Internet, you will find that people reinvent this wheel over and over, write almost the same method over and over. We must protect the Earth from global warming! :-)

As a small sign of gratitude, I won't then write an issue about a large PR to concurrentunit (Excellent library BTW)

magicprinc commented 2 years ago

Your wish is my command. Tell me if I should send an PR.

Tembrel commented 2 years ago

Not up to me.