@interface MyObject : NSObject {
NSDate * requestTimeOutDate;
NSInteger timeOutLength;
id someObject;
id valueImWatching;
}
@implementation MyObject
-(void) timeOut: someObject {
if ([[NSDate date] timeIntervalSinceDate: requestTimeOutDate] > timeOutLength)
{
NSLog(@"timed out");
// do something, or nothing.
else
{
// attempt the action I'm looking for.
if (valueImWatching) {
// do something or just exit.
} else {
NSLog(@"call again");
[NSObject cancelPreviousPerformRequestsWithTarget:self]; //selector:_cmd object: someObject];
[self performSelector:_cmd withObject: someObject afterDelay:1.0];
}
}
}
- (void) myFirstMethod {
valueImWatching = nil;
someObject = [SomeObject new]; //set it up appropriately.
requestTimeOutDate = [[NSDate date] retain]; //now
timeOutLength = 5; // seconds of timeout
[self timeOut: someObject];
}