[External] : Re: Synchronous executor interface
Robert Engels
rengels at ix.netcom.com
Fri Aug 11 22:35:25 UTC 2023
Atilla,
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.
Systems designed the way you propose are really hard to reason about except for the original designer. Similar to DI and micro services.
The system’s intent and operation are obscured.
> On Aug 11, 2023, at 5:04 PM, Attila Kelemen <attila.kelemen85 at gmail.com> wrote:
>
>
> 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/20230811/8b16cf67/attachment.htm>
More information about the loom-dev
mailing list