According to the documentation for the NSRunLoop
method run
:
Manually removing all known input sources and timers from the run loop is not a guarantee that the run loop will exit. OS X can install and remove additional input sources as needed to process requests targeted at the receiver’s thread. Those sources could therefore prevent the run loop from exiting.
If you want the run loop to terminate, you shouldn't use this method. Instead, use one of the other run methods and also check other arbitrary conditions of your own, in a loop. A simple example would be:
BOOL shouldKeepRunning = YES; // global NSRunLoop *theRL = [NSRunLoop currentRunLoop]; while (shouldKeepRunning && [theRL runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]]);
where
shouldKeepRunning
is set toNO
somewhere else in the program.
Obviously, rather than using shouldKeepRunning
, you might use ![self isFinished]
instead, but it illustrates the point.
If you're going to enable multiple concurrent operations (and for the sake of efficiently running all of your B requests, you should seriously consider this), you might want to take a look at what AFNetworking did, which was (a) create a single dedicated thread for networking requests and start the run loop there, (b) schedule all network requests on this run loop; and (c) make the operations concurrent (e.g. isConcurrent
returns YES
).