ScopedValue structured forking/forwarding API
Andrew Haley
aph-open at littlepinkcloud.com
Fri Jul 11 17:11:53 UTC 2025
On 11/07/2025 11:57, Nikita Bobko wrote:
> Please note that the API shape that I'm suggesting replicates
> StructuredTaskScope, and it doesn't do anything that couldn't be already
> achieved with the existing StructuredTaskScope API (Or I explained it
> poorly).
I guess that Carrier.run(), ScopedValue.snapshot(), and
Snapshot.forward() would do some sort of handshake to make sure that
every Snapshot has been join()ed at the end of Carrier.run(). I guess
that would work if we could figure out a sound way to do it, but at
present we don't need to do much of this. I take your point about the
StructuredTaskScope complications, though.
I'm hoping that at some point in the future we can get a secure form of
try with resources, one that doesn't rely on the user to call close(),
but that's a long way off.
Most people who have asked about capturing scoped values have wanted to
use them in an unstructured way, but your request is quite different.
Given that a StructuredTaskScope can work with any ThreadFactory, why do
you need to replicate its working? What do you need to do differently?
I'm still curious about this:
> However, it is straightforward to create a scoped value class of your
> own that has any properties you wish, including different inheritance
> rules. Given a ScopedValue.Carrier that binds some values, start your
> thread with aCarrier.run(task). Would this work for you?
--
Andrew Haley (he/him)
Java Platform Lead Engineer
More information about the loom-dev
mailing list