@Beta public class InterruptingImmediateSupplier<T> extends java.lang.Object implements ImmediateSupplier<T>, DeferredSupplier<T>
ImmediateSupplierby interrupting the thread before calling
Supplier.get(). If the call succeeds, the result is returned. If the call throws any trace including an
RuntimeInterruptedException(ie the call failed due to the interruption, typically because it tried to wait) then this class concludes that there is no value available immediately and returns
Maybe.absent(). If the call throws any other error, that is returned. The interruption is cleared afterwards (unless the thread was interrupted when the method was entered).
Note that some "immediate" methods, such as
Semaphore.acquire() when a semaphore is available,
will throw if the thread is interrupted. Typically there are workarounds, for instance:
if (semaphore.tryAcquire()) semaphore.acquire();.
|Modifier and Type||Class and Description|
|Constructor and Description|
|Modifier and Type||Method and Description|
public InterruptingImmediateSupplier(com.google.common.base.Supplier<T> nestedSupplier)
Maybe.absent()if the value requires blocking, or throws
ImmediateSupplier.ImmediateUnsupportedExceptionif it cannot be determined whether the value requires blocking or not.
Maybe.absent() returned here indicates that a value definitively is pending, just it is not yet available,
and an attempt to
Maybe.get() it should throw an
it can be created with
avoid creating traces (or simply with
This is in contrast with this method throwing a
ImmediateSupplier.ImmediateUnsupportedException which should be done
if the presence of an eventual value cannot even be determined in a non-blocking way.
Implementations of this method should typically catch the former exception if encountered and return a
Maybe.absent() wrapping it, whereas
ImmediateSupplier.ImmediateUnsupportedException instances should be propagated.
public T get()
public static <T> InterruptingImmediateSupplier<T> of(java.lang.Object o)