Using Timed Waits
An
RWTIOUTrap can also be used to implement a timed wait on an IOU result. This capability is significant because the
RWTIOUResult class does not allow a time-limit to be placed on a redemption operation. The following code demonstrates this capability:
Example 47 – Implementing a timed wait on an IOU result
#include <rw/thread/RWTThreadIOUFunction.h>
#include <rw/itc/RWTIOUResult.h>
#include <rw/itc/RWTIOUTrap.h>
#include <iostream>
using namespace std;
int func()
{
int result = 0;
// Wait for a while...
rwSleep(3000);
return result;
}
void main()
{
RWTIOUTrap<int> trap;
RWTThreadIOUFunction<int> thread;
thread = RWTThreadIOUFunction<int>::make(func);
thread.start();
trap.setTrap(thread.result());
RWTIOUResult<int> iou;
// Wait 1 second, complain and repeat...
while(RW_THR_COMPLETED != trap.getNext(iou,1000)) {
cout << "Timed out! Retrying..." << endl;
}
cout << "IOU closed — Operation Complete!" << endl;
}
To see another example of
RWTIOUTrap usage, refer to
Waiting for IOUs.