Interface SyncVar<T>

Type Parameters:
T - variable type
All Known Implementing Classes:
SyncVarImpl

public interface SyncVar<T>
A variable intended to be used by multiple threads.
  • Method Details

    • createSyncVar

      @NotNull static <T> @NotNull SyncVar<T> createSyncVar(@Nullable T value)
    • createSyncVar

      @NotNull static <T> @NotNull SyncVar<T> createSyncVar()
    • get

      @Nullable T get()
      Synchronised get.
      Returns:
      value of this variable
    • doSynchronised

      void doSynchronised(@NotNull @NotNull Consumer<@NotNull SyncVar<T>> consumer)
      Execute given consumer synchronised on this variable.
      Parameters:
      consumer - Consumer
    • consumeIfNotNull

      boolean consumeIfNotNull(@NotNull @NotNull Consumer<@NotNull T> consumer)
      locks on this variable and checks if its value is not null. If that is the case, given consumer will be executed, while keeping the lock on the variable.
      Parameters:
      consumer - to consume the variable
      Returns:
      true if given consumer was executed. false otherwise.
    • setIfNull

      boolean setIfNull(@Nullable T value)
      Sets the variables value if it is null. thread safe.
      Parameters:
      value - the value to set
      Returns:
      true if this variables value was null
    • setIfNull

      boolean setIfNull(@NotNull @NotNull Supplier<T> supplier)
      Same as setIfNull(Object) but with a Supplier.
    • set

      void set(@Nullable T value)
      Synchronised set.
      Parameters:
      value - the variables value