Created
August 5, 2010 17:24
-
-
Save kylesluder/510055 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Foundation/Foundation.h> | |
@interface BusyWaiter : NSObject | |
{ | |
BOOL _done; | |
} | |
- (void)markDone; | |
- (BOOL)isDone; | |
@end | |
@implementation BusyWaiter | |
- (void)markDone; { | |
NSLog(@"Marked done."); | |
_done = YES; | |
} | |
- (BOOL)isDone; { | |
return _done; | |
} | |
@end | |
int main(int argc, char **argv) { | |
NSAutoreleasePool *p = [NSAutoreleasePool new]; | |
NSRunLoop *currentRunLoop = [NSRunLoop currentRunLoop]; | |
BusyWaiter *b = [BusyWaiter new]; | |
[b performSelector:@selector(markDone) withObject:nil afterDelay:1.0f]; | |
while (![b isDone]) { | |
if(![[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]) | |
break; | |
NSLog(@"Ran."); | |
} | |
[p drain]; | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment