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 | Description |
|---|---|
AsyncConditions() |
Same as AsyncConditions(1).
|
AsyncConditions(int numEvalBlocks) |
Instantiates an AsyncConditions instance with the specified number
of evaluate blocks.
|
| Modifier and Type | Method | 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,
java.util.concurrent.TimeUnit unit) |
Deprecated.
use
await(double) instead |
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 evaluatepublic void await()
throws java.lang.InterruptedException,
java.lang.Throwable
await(1).java.lang.InterruptedExceptionjava.lang.Throwablepublic void await(double seconds)
throws java.lang.InterruptedException,
java.lang.Throwable
seconds - the timeout (in seconds)java.lang.InterruptedException - if the calling thread is interruptedjava.lang.Throwable - the first exception thrown by an evaluate block@Deprecated
public void await(int value,
java.util.concurrent.TimeUnit unit)
throws java.lang.InterruptedException,
java.lang.Throwable
await(double) insteadjava.lang.InterruptedException - if the calling thread is interruptedjava.lang.Throwable - the first exception thrown by an evaluate blockCopyright © 2018. All rights reserved