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>

public class OnceValue<T> extends Object implements Supplier<T>
The OnceValue class implements Go's sync.OnceValue. A Supplier wrapper that ensures the wrapped Supplier is executed only once.
  • Constructor Details

    • OnceValue

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

    • get

      public 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<T>
      Returns:
      the result supplied by the wrapped Supplier on its first execution, or null on subsequent calls