Executor like scope

Attila Kelemen attila.kelemen85 at gmail.com
Mon Jun 5 18:19:42 UTC 2023


Hi,

I would like to ask for a new type of scope in addition to
`StructuredTaskScope` which we already have.

For the general need, please consider the following scenario:

1. Let's assume there is a simple server which schedules a background job
for a specific HTTP request.

2. In such a server, we might assume that each HTTP request handler is
running in a particular scope.

Notice that, if we are scheduling a new job in the HTTP request, then we
can't do it in a scope, because the scheduled job has a longer lifetime
than the current scope, and even if we had an outer STS, we could not
directly call that, because STS does not allow a call from a child scope.
However, we might want to use the main application scope, which we can't,
if we just used a usual executor.

Still, I have created a POC [1] relying on STS that provides the equivalent
feature, I'm asking for. However, the problem with this is that it requires
a channel, which is needlessly inefficient. That is, an implementation of
this feature in the JDK could look very similar to STS, but would allow the
call from a child scope, and would return a `CompletableFuture` (or maybe
something similar) instead.

[1]: https://gist.github.com/kelemen/192dfd56bf9bd814d267cd70df0268f0

Attila
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230605/ab1d0bec/attachment.htm>


More information about the loom-dev mailing list