Class OnceValues<S,T>

java.lang.Object
io.javago.sync.OnceValues<S,T>
Type Parameters:
S - the type of the first value
T - the type of the second value
All Implemented Interfaces:
Supplier<OnceValues.Values<S,T>>

public class OnceValues<S,T> extends Object implements Supplier<OnceValues.Values<S,T>>
The OnceValues class implements Go's sync.OnceValues. A Supplier wrapper that ensures the wrapped Supplier is executed only once and returns a pair of values.
  • Constructor Details

    • OnceValues

      public OnceValues(Supplier<OnceValues.Values<S,T>> supplier)
      Constructs a new OnceValues that will wrap the given Supplier.
      Parameters:
      supplier - the Supplier to be wrapped and executed only once
  • Method Details

    • get

      public OnceValues.Values<S,T> get()
      Executes the wrapped Supplier only once. If this method is called multiple times, the wrapped Supplier will only be executed the first time and its result will be returned. Subsequent calls will return null.
      Specified by:
      get in interface Supplier<S>
      Returns:
      the result supplied by the wrapped Supplier on its first execution, or null on subsequent calls