Skip to content

Instantly share code, notes, and snippets.

@seivan
Created June 30, 2015 07:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save seivan/0becfffbb1d7665cebfe to your computer and use it in GitHub Desktop.
Save seivan/0becfffbb1d7665cebfe to your computer and use it in GitHub Desktop.
/*
+(BOOL)runLoopUntilTestPassesWithBlock:(__SHTestCaseInternalTestCaseConditional)theBlock withTimeOut:(NSTimeInterval)theTimeout; {
NSParameterAssert(theBlock);
NSParameterAssert(theTimeout >= 0);
NSDate * timeoutDate = [NSDate dateWithTimeIntervalSinceNow:theTimeout];
NSTimeInterval timeoutTime = [timeoutDate timeIntervalSinceReferenceDate];
NSTimeInterval currentTime = 0.0;
*/
for (currentTime = [NSDate timeIntervalSinceReferenceDate];
(theBlock() == NO && currentTime < timeoutTime);
currentTime = [NSDate timeIntervalSinceReferenceDate]) {
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate dateWithTimeIntervalSinceNow:0.1]];
}
/* return currentTime <= timeoutTime;
}
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment