Interface Transfer<T>
-
public interface Transfer<T>A utility for transferring a value between separate producer and consumer executions.This construct is equivalent to
LinkedBlockingQueue, but for a single value and is non-blocking.It is important to
close()transfers when done to release any waiting producers or consumers.- Since:
- 1.10
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description Operationclose()Releases any waiting put/get operations.static <T> Transfer<T>create()Creates a transfer.default Promise<java.util.Optional<T>>get()Consumes a transferred value.Promise<java.lang.Boolean>put(T value)Writes the value for transfer.Promise<java.util.Optional<T>>tryGet(java.time.Duration timeout)Consumes a transferred value, waiting up to the given timeout.
-
-
-
Method Detail
-
create
static <T> Transfer<T> create()
Creates a transfer.- Type Parameters:
T- the transferred value type- Returns:
- a transfer
-
put
Promise<java.lang.Boolean> put(T value)
Writes the value for transfer.The returned promise will complete with true when the value is consumed. It will complete with false if the transfer is closed before the value is consumed.
- Parameters:
value- the value to transfer- Returns:
- a promise indicating whether the value was transferred
-
tryGet
Promise<java.util.Optional<T>> tryGet(java.time.Duration timeout)
Consumes a transferred value, waiting up to the given timeout.The returned promise will complete with an empty optional if the timeout elapses or if the transfer is closed. It will complete with a non-empty optional if a value was transferred.
- Parameters:
timeout- how long to wait for a value to be transferred- Returns:
- a promise for the transferred value
-
get
default Promise<java.util.Optional<T>> get()
Consumes a transferred value.The returned promise will complete with an empty optional if the transfer is closed. It will complete with a non-empty optional if a value was transferred.
- Returns:
- a promise for the transferred value
-
close
Operation close()
Releases any waiting put/get operations.After closure, all subsequent put/get operations return immediately.
- Returns:
- an operation that closes the transfer
-
-