<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div dir="ltr"></div><div dir="ltr">Atilla,</div><div dir="ltr"><br></div><div dir="ltr">Please do not write code like that. If you have a “service” put it behind an api/facade and do any concurrency controls there - make it a simple method call for the caller/user. </div><div dir="ltr"><br></div><div dir="ltr">Systems designed the way you propose are really hard to reason about except for the original designer.  Similar to DI and micro services. </div><div dir="ltr"><br></div><div dir="ltr">The system’s intent and operation are obscured. </div><div dir="ltr"><br><blockquote type="cite">On Aug 11, 2023, at 5:04 PM, Attila Kelemen <attila.kelemen85@gmail.com> wrote:<br><br></blockquote></div><blockquote type="cite"><div dir="ltr"><div dir="ltr">Yeah, but you have a new interface there (and considerably more complicated than my proposal), and that is what I'm saying that you can't just get away with a function and similar. If custom interfaces are allowed, then there is nothing to talk about, since I have already provided one.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Pedro Lamarão <<a href="mailto:pedro.lamarao@prodist.com.br">pedro.lamarao@prodist.com.br</a>> ezt írta (időpont: 2023. aug. 11., P, 23:22):<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="ltr"></div><div class="gmail_quote"><div dir="ltr" class="gmail_attr">Em sex., 11 de ago. de 2023 às 15:26, Attila Kelemen <<a href="mailto:attila.kelemen85@gmail.com" target="_blank">attila.kelemen85@gmail.com</a>> escreveu:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr">To elaborate more, your executor can be created for any type, but that is almost pointless for an executor, because an executor instance has to support all types. Similarly you can't create a simplified `ExecutorService` as `Function<Callable<T>, Future<T>>`. Such an executor would be very limited in usefulness, because to simply put: An executor cannot have a type argument.</div></blockquote><div><br></div><div>The following compiles just fine. </div></div><div><br></div><div><span style="font-family:monospace">import java.util.function.Function;</span><br></div><div><font face="monospace">import java.util.function.Supplier;<br><br>interface Executor {<br>    default <T> T run(Supplier<T> s, Function<Supplier<T>, Supplier<T>> mapper) {<br>        return mapper.apply(s).get();<br>    }<br>}<br><br>class Wrap {<br>    public static void main(String[] args) {<br>        Executor z = new Executor() {};<br>        String x = z.run(() -> "hi", Wrap::withMessage);<br>        System.out.println(x);<br>    }<br><br>    static <T> Supplier<T> withMessage(Supplier<T> s) {<br>        return () -> {<br>            System.out.println("before");<br>            try {<br>                return s.get();<br>            } finally {<br>                System.out.println("after");<br>            }<br>        };<br>    }<br>}</font><br></div><div><div><br></div><span class="gmail_signature_prefix">-- </span><br><div dir="ltr" class="gmail_signature"><div dir="ltr"><div>Pedro Lamarão</div></div></div></div></div>
</blockquote></div>
</div></blockquote></body></html>