Almost the only option for us is sleep(n)
(if you are familiar with SIGNAL, you can also use it). We are familiar with it, so let's pass it.
There is resource called semaphore
, use it can make your code more robust and more efficient.
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://www.google.com"]];
[request setHTTPShouldUsePipelining:YES];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
[NSURLConnection sendAsynchronousRequest:request queue:queue completionHandler:^(NSURLResponse *resp, NSData *data, NSError *error) {
NSLog(@"Data: %@", data);
dispatch_semaphore_signal(sema);
}];
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
dispatch_release(sema);
NSLog(@"Over");
Please note that program will stop at dispatch_semaphore_wait
.
Use it in your test code, make your test more fast and more robust. ;)