Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy won't this loop exit
    primarykey
    data
    text
    <p>My assumption is that the <code>operation</code>s are running asynchronously on a separate thread, but the loop never exits, so something is not as I assumed.</p> <pre><code>/** Checks if we can communicate with the APIs @result YES if the network is available and all of the registered APIs are responsive */ - (BOOL)apisAvailable { // Check network reachability if (!_connectionAvailable) { return NO; } // Check API server response NSMutableSet *activeOperations = [[NSMutableSet alloc] init]; __block NSInteger successfulRequests = 0; __block NSInteger failedRequests = 0; for (AFHTTPClient *httpClient in _httpClients) { // Send heart beat request NSMutableURLRequest *request = [httpClient requestWithMethod:@"GET" path:@"" parameters:nil]; AFHTTPRequestOperation *operation = [[AFHTTPRequestOperation alloc] initWithRequest:request]; [operation setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject) { // Server returned good response successfulRequests += 1; } failure:^(AFHTTPRequestOperation *operation, NSError *error) { // Server returned bad response failedRequests += 1; }]; [operation start]; [activeOperations addObject:operation]; } // Wait for heart beat requests to finish while (_httpClients.count &gt; (successfulRequests + failedRequests)) { // Wait for each operation to finish, one at a time //usleep(150); [NSThread sleepForTimeInterval:0.150]; } // Check final results if (failedRequests &gt; 0) { return NO; } return YES; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload