Package de.linusdev.lutils.thready.var
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 Summary
Modifier and TypeMethodDescriptionbooleanconsumeIfNotNull(@NotNull Consumer<@NotNull T> consumer) locks on this variable and checks if its value is notnull.static <T> @NotNull SyncVar<T>static <T> @NotNull SyncVar<T>createSyncVar(T value) voiddoSynchronised(@NotNull Consumer<@NotNull SyncVar<T>> consumer) Execute givenconsumersynchronised on this variable.get()Synchronised get.voidSynchronised set.booleanSame assetIfNull(Object)but with aSupplier.booleanSets the variables value if it isnull.
-
Method Details
-
createSyncVar
-
createSyncVar
-
get
Synchronised get.- Returns:
- value of this variable
-
doSynchronised
Execute givenconsumersynchronised on this variable.- Parameters:
consumer-Consumer
-
consumeIfNotNull
locks on this variable and checks if its value is notnull. If that is the case, givenconsumerwill be executed, while keeping the lock on the variable.- Parameters:
consumer- to consume the variable- Returns:
trueif givenconsumerwas executed.falseotherwise.
-
setIfNull
Sets the variables value if it isnull. thread safe.- Parameters:
value- the value to set- Returns:
trueif this variables value wasnull
-
setIfNull
Same assetIfNull(Object)but with aSupplier. -
set
Synchronised set.- Parameters:
value- the variables value
-