Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Processing all run loop modes (this is essentially GHUnit's version of '... #47

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/EXPExpect.m
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,9 @@ - (void)applyMatcher:(id<EXPMatcher>)matcher to:(NSObject **)actual {
} else {
BOOL matchResult = NO;
if(self.asynchronous) {
NSUInteger runIndex = 0;
NSArray *runLoopModes = [NSArray arrayWithObjects:NSDefaultRunLoopMode, NSRunLoopCommonModes, nil];
NSTimeInterval checkEveryInterval = 0.01;
NSTimeInterval timeOut = [Expecta asynchronousTestTimeout];
NSDate *expiryDate = [NSDate dateWithTimeIntervalSinceNow:timeOut];
while(1) {
Expand All @@ -106,7 +109,13 @@ - (void)applyMatcher:(id<EXPMatcher>)matcher to:(NSObject **)actual {
if(!failed || ([(NSDate *)[NSDate date] compare:expiryDate] == NSOrderedDescending)) {
break;
}
[[NSRunLoop currentRunLoop] runUntilDate:[NSDate dateWithTimeIntervalSinceNow:0.01]];
@autoreleasepool {
NSString *mode = [runLoopModes objectAtIndex:(runIndex++ % [runLoopModes count])];
if (!mode || ![[NSRunLoop currentRunLoop] runMode:mode beforeDate:[NSDate dateWithTimeIntervalSinceNow:checkEveryInterval]]) {
// If there were no run loop sources or timers then we should sleep for the interval
[NSThread sleepForTimeInterval:checkEveryInterval];
}
}
OSMemoryBarrier();
*actual = self.actual;
}
Expand Down