Add Acquirable#isLocal

Signed-off-by: TheMode <themode@outlook.fr>
This commit is contained in:
TheMode 2021-09-11 20:24:11 +02:00
parent 42f4678db0
commit 5106927b10

View File

@ -98,11 +98,19 @@ public interface Acquirable<T> {
* {@link Optional#empty()} otherwise
*/
default @NotNull Optional<T> local() {
if (Thread.currentThread() == getHandler().getTickThread())
return Optional.of(unwrap());
if (isLocal()) return Optional.of(unwrap());
return Optional.empty();
}
/**
* Gets if the acquirable element is local to this thread
*
* @return true if the element is linked to the current thread
*/
default boolean isLocal() {
return Thread.currentThread() == getHandler().getTickThread();
}
/**
* Locks the acquirable element, execute {@code consumer} synchronously and unlock the thread.
* <p>