public class AsyncConditions
extends java.lang.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, TimeUnit.SECONDS).
|
void |
await(int timeout,
java.util.concurrent.TimeUnit unit)
Waits until all evaluate blocks have completed or the specified timeout
expires.
|
void |
evaluate(java.lang.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(java.lang.Runnable block)
block
- the code block to evaluatejava.lang.Throwable
public void await() throws java.lang.InterruptedException, java.lang.Throwable
java.lang.InterruptedException
java.lang.Throwable
public void await(int timeout, java.util.concurrent.TimeUnit unit) throws java.lang.InterruptedException, java.lang.Throwable
java.lang.InterruptedException
- if the calling thread is interruptedjava.lang.Throwable
- the first exception thrown by an evaluate blockCopyright © 2014. All rights reserved