Created
August 25, 2014 15:47
-
-
Save karpelcevs/7fa7f9e725a4cd3665d9 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
@implementation XCTest (Async) | |
+ (NSTimeInterval)waitTillReady:(BOOL (^)())isReady orTimeout:(NSTimeInterval)seconds | |
{ | |
NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate]; | |
NSDate *loopUntil = [NSDate dateWithTimeIntervalSinceNow:seconds]; | |
while (!isReady() && [loopUntil timeIntervalSinceNow] > 0) { | |
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:loopUntil]; | |
} | |
NSTimeInterval finish = [NSDate timeIntervalSinceReferenceDate]; | |
return (finish - start); | |
} | |
+ (void)waitForTimeout:(NSTimeInterval)seconds | |
{ | |
NSDate *loopUntil = [NSDate dateWithTimeIntervalSinceNow:seconds]; | |
while ([loopUntil timeIntervalSinceNow] > 0) { | |
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:loopUntil]; | |
} | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment