Package io.javago.sync
Class OnceValue<T>
java.lang.Object
io.javago.sync.OnceValue<T>
- Type Parameters:
T
- the type of results supplied by this supplier
- All Implemented Interfaces:
Supplier<T>
The
OnceValue
class implements Go's sync.OnceValue
.
A Supplier
wrapper that ensures the wrapped Supplier
is executed only once.-
Constructor Summary
Constructors -
Method Summary
-
Constructor Details
-
OnceValue
Constructs a newOnceValue
that will wrap the givenSupplier
.- Parameters:
func
- theSupplier
to be wrapped and executed only once
-
-
Method Details
-
get
Executes the wrappedSupplier
only once. If this method is called multiple times, the wrappedSupplier
will only be executed the first time and its result will be returned. Subsequent calls will returnnull
.
-