Loom EA and using a custom Joiner

Mika Moilanen mika.a.moilanen at gmail.com
Fri Nov 15 07:47:34 UTC 2024


Hello,

I've been playing around with the latest EA (
https://openjdk.org/jeps/8340343) build with Joiners et al.
I'm building a small utility which reads a list of http requests from a
file and runs them concurrently. These tasks have an associated test which
is an assertion about the http response.
Tasks can either succeed or they can fail in two ways:

1) expected failure: test or its execution can fail
2) something unexpected outside of the test execution e.g NPE happens.

Task are self-contained and TaskResponse contains all the data needed for
reporting the outcome to the user:

sealed interface TaskResult {
  record Success(....) ...
  record TestFailed(... ) .. // test failed
  record Failure(...) ... // something else failed e.g an exception during
the http call
}

In case of successfull SubTask I need to check if the TaskResult is
TestFailed or Failure, and shutdown the scope preventing processing of
tasks, and report about the outcome.
In case of any SubTask if failing I need only the exception from the last
SubTask::exception().

I started with a StructuredTaskScope.Joiner.allUntil(<a predicate which
examines TaskResult>) but noticed that join() doesn't throw, and thus
proceeded in implementing a custom Joiner which stores the last exception
and overrides result and onComplete - methods.

Just wanted to verify: Is it the "idiomatic" way of using the new preview
api, or is there some existing Joiner which would offer the functionality
I'm after?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20241115/eda15b10/attachment.htm>


More information about the loom-dev mailing list