public class AsyncConditions extends Object
Example:
// create object under specification def machine = new Machine() def conds = new AsyncConditions() // register async callback machine.workDone >> { result -> conds.evaluate { assert result == WorkResult.OK // could add more explicit conditions here } } when: machine.start() then: // wait for the evaluation to complete // any exception thrown in the evaluate block will be rethrown from this method conds.await() cleanup: // shut down all threads machine?.shutdown()
Constructor and Description |
---|
AsyncConditions()
Same as AsyncConditions(1).
|
AsyncConditions(int numEvalBlocks)
Instantiates an AsyncConditions instance with the specified number
of evaluate blocks.
|
Modifier and Type | Method and Description |
---|---|
void |
await()
Same as
await(1) . |
void |
await(double seconds)
Waits until all evaluate blocks have completed or the specified timeout
(in seconds) expires.
|
void |
await(int value,
TimeUnit unit)
Deprecated.
use
await(double) instead |
void |
evaluate(Runnable block)
Evaluates the specified block, which is expected to contain
one or more explicit conditions (i.e.
|
public AsyncConditions()
public AsyncConditions(int numEvalBlocks)
Note: One evaluate block may contain multiple conditions.
numEvalBlocks
- the number of evaluate blocks that await()
should wait forpublic void evaluate(Runnable block)
block
- the code block to evaluatepublic void await(double seconds) throws Throwable
seconds
- the timeout (in seconds)InterruptedException
- if the calling thread is interruptedThrowable
- the first exception thrown by an evaluate block@Deprecated public void await(int value, TimeUnit unit) throws Throwable
await(double)
insteadInterruptedException
- if the calling thread is interruptedThrowable
- the first exception thrown by an evaluate block