ScopedValue: Capturing current bindings

Attila Kelemen attila.kelemen85 at gmail.com
Fri Jun 2 17:54:30 UTC 2023


> OK, so it's possible for application code called from a framework to
> override the caller's context, as long as that context was a parent
> of the current context. That seems like a significant weakening of
> the guarantees that scoped values provide.
>
>
Yes, and a few days ago I would have also said that it might weaken the
guarantees. However, you might have missed it in the infinite sea of
emails, but I have actually figured out a way how this can be implemented
[1]. The only problem is that the implementation is very inefficient
compared to the fact that it effectively just does what you wrote:
"override the caller's context, as long as that context was a parent of the
current context" (does it with an otherwise completely pointless
parallelization). See `CapturedScopes.withCurrentContext` (I called this
method `withCapturedContext` in a previous email, sorry for the
inconsistency).

That is, providing this feature in the JDK would not weaken any guarantees.

[1]: https://gist.github.com/kelemen/5a334e3d189f91355c4615ad94d0b6fd
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/loom-dev/attachments/20230602/3c7922b1/attachment.htm>


More information about the loom-dev mailing list