This is related to my previous question, but different enough that I figured I\'d throw it into a new one. I have some code that runs async on a custom queue, then executes
An alternate method, using semaphores and runloop churning. Note that dispatch_semaphore_wait returns nonzero if it times out.
- (void)testFetchSources
{
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
[MyObject doSomethingAsynchronousWhenDone:^(BOOL success) {
STAssertTrue(success, @"Failed to do the thing!");
dispatch_semaphore_signal(semaphore);
}];
while (dispatch_semaphore_wait(semaphore, DISPATCH_TIME_NOW))
[[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode
beforeDate:[NSDate dateWithTimeIntervalSinceNow:10]];
dispatch_release(semaphore);
}