Skip to content

Instantly share code, notes, and snippets.

@kylesluder
Created August 5, 2010 17:24
Show Gist options
  • Save kylesluder/510055 to your computer and use it in GitHub Desktop.
Save kylesluder/510055 to your computer and use it in GitHub Desktop.
#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