T - the variable's typepublic class BlockingVariable<T>
extends java.lang.Object
Example:
// create object under specification
def machine = new Machine()
def result = new BlockingVariable<WorkResult>
// register async callback
machine.workDone << { r ->
result.set(r)
}
when:
machine.start()
then:
// blocks until workDone callback has set result, or a timeout expires
result.get() == WorkResult.OK
cleanup:
// shut down all threads
machine?.shutdown()
| Constructor and Description |
|---|
BlockingVariable()
Same as BlockingVariable(1, TimeUnit.SECONDS).
|
BlockingVariable(int timeout)
Instantiates a BlockingVariable with the specified timeout in seconds.
|
BlockingVariable(int timeout,
java.util.concurrent.TimeUnit unit)
Instantiates a BlockingVariable with the specified timeout.
|
public BlockingVariable()
public BlockingVariable(int timeout)
timeout - the timeout (seconds) for calls to get().public BlockingVariable(int timeout,
java.util.concurrent.TimeUnit unit)
timeout - the timeout for calls to get().unit - the time unitpublic T get() throws java.lang.InterruptedException
java.lang.InterruptedException - if the calling thread is interruptedpublic void set(T value)
value - the value to be set for this variableCopyright © 2013. All rights reserved