[External] : Re: Synchronous executor interface

Attila Kelemen attila.kelemen85 at gmail.com
Fri Aug 11 22:03:42 UTC 2023


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.

Pedro Lamarão <pedro.lamarao at prodist.com.br> ezt írta (időpont: 2023. aug.
11., P, 23:22):

> Em sex., 11 de ago. de 2023 às 15:26, Attila Kelemen <
> attila.kelemen85 at gmail.com> escreveu:
>
>> 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.
>>
>
> The following compiles just fine.
>
> import java.util.function.Function;
> import java.util.function.Supplier;
>
> interface Executor {
>     default <T> T run(Supplier<T> s, Function<Supplier<T>, Supplier<T>>
> mapper) {
>         return mapper.apply(s).get();
>     }
> }
>
> class Wrap {
>     public static void main(String[] args) {
>         Executor z = new Executor() {};
>         String x = z.run(() -> "hi", Wrap::withMessage);
>         System.out.println(x);
>     }
>
>     static <T> Supplier<T> withMessage(Supplier<T> s) {
>         return () -> {
>             System.out.println("before");
>             try {
>                 return s.get();
>             } finally {
>                 System.out.println("after");
>             }
>         };
>     }
> }
>
> --
> Pedro Lamarão
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230812/95f18a8d/attachment-0001.htm>


More information about the loom-dev mailing list