Skip to content

Instantly share code, notes, and snippets.

@endoze
Created November 5, 2012 20:11
Show Gist options
  • Save endoze/4020065 to your computer and use it in GitHub Desktop.
Save endoze/4020065 to your computer and use it in GitHub Desktop.
Async Unit Testing Helper Method
# found at http://www.infinite-loop.dk/blog/2011/04/unittesting-asynchronous-network-access/
- (BOOL)waitForCompletion:(NSTimeInterval)timeoutSecs {
NSDate *timeoutDate = [NSDate dateWithTimeIntervalSinceNow:timeoutSecs];
do {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:timeoutDate];
if([timeoutDate timeIntervalSinceNow] < 0.0)
break;
} while (!done);
return done;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment