I am looking to decorate a BiFunction with a retry. I thought I saw an example of it when I was looking for something else, but my current searches are not finding anything. Would you happen to have an example of this somewhere?
can u please give an example of the BiFunction ? meanwhile u can do something like :
BiFunction<String,String,String> testBiFunction= (s1,s2)-> s1.toUpperCase();
Retry.ofDefaults("test").executeSupplier(()->testBiFunction.apply("test1","test2"));
Let me know if it was what u r asking for ?
Thanks for the reply.
myServiceCall2(arg1, arg2) or
myServiceCall3(arg1, arg2, arg3)
All of the examples in the documentation use Supplier. I am just looking for examples of things more complex. Function was easy enough to figure out tho.
In your above example, for multi arg methods, is it best to just go straight to execute instead of using the decorators?
You can almost always use decorateSupplier to decorate your function/method with 2 or more arguments.
Just use Supplier<Result> decoratedMethod = circuitBreaker.decorateSupplier(() -> class.myServiceCall3(arg1, arg2, arg3))
That's exactly what I was looking for. Thanks.
From a design perspective, I'm curious why you chose to include decorateFunction when presumably you could use decorateSupplier for that as well?
When I started Resilience4j I wanted to add support for at least the basic Java8 functional interfaces. At that point in time I wasn't sure that Supplier, Callable and Runnable is almost sufficient. Bifunction was not part of it. Vavr provides additional functional interfaces for functions with arguments from 1 to 8. But I never needed them.
Feel free to close the issue, if the answer is fine for you.
Cool. Thanks for the insight, and thanks for the great library.