Class Scoped<T>
java.lang.Object
gov.nasa.jpl.aerie.merlin.framework.Scoped<T>
- All Implemented Interfaces:
Supplier<T>
A dynamically-scoped cell.
Values pushed into the cell are strictly popped in the same order,
and the lifetime of each value is tied to the call stack.
See the related concept of
scoped variables
in Project Loom.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic final record -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Scoped<T> create()Create a dynamically-scoped cell containing values of typeScoped.get()Gets the current value of the dynamic cell.Set a value in this cell, returning anAutoCloseableresource restoring the previous value on close.
-
Method Details
-
create
Create a dynamically-scoped cell containing values of typeScoped.- Type Parameters:
T- The type of value this cell will contain.- Returns:
- A new cell that can contain values of type
Scoped.
-
get
Gets the current value of the dynamic cell. Throws an exception if nobody up-stack is currently serving this cell.- Specified by:
getin interfaceSupplier<T>- Throws:
Scoped.EmptyDynamicCellException
-
set
Set a value in this cell, returning anAutoCloseableresource restoring the previous value on close.This method should always be used in a try-with-resources statement:
try (final var scope = cell.set(value)) { // ... }
-