Example
Typical uses of the close() and setException() functions are shown in the code fragment in Example 44.
Example 44 – Closing an IOU
void async_operation(RWTIOUEscrow<int>& iou)
{
try {
int result=0;
// Perform some operation to calculate result...
// Close the escrow
iou.close(result);
}
catch(...) {
iou.setException("Unexpected Exception");
}
}
The IOU object is intended as a “one-shot” communication mechanism. An IOU instance can only be closed once during its life-span—it is not possible to reset or reuse an IOU. Any attempt to do so produces an RWTHREscrowAlreadyClosed exception.
The RWTIOUEscrow class also has several functions that applications can call to query the status of an IOU object:
*aborted() — Returns true if a client has requested that the operation be aborted.
*closeable() — Returns true if the IOU has not been aborted and has not yet been closed.
*closed() — Returns true if the IOU has been closed.
*inError() — Returns true if the IOU was closed using setException().
*redeemed() — Returns true if any thread has successfully redeemed the IOU to retrieve its value.