Skip to content

Commit

Permalink
Don't allow task count to go below zero.
Browse files Browse the repository at this point in the history
  • Loading branch information
samvermette committed Jun 2, 2013
1 parent fd0cfa1 commit 98ccae4
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions SVHTTPRequest/SVHTTPRequest.m
Expand Up @@ -29,7 +29,7 @@ - (NSString*)encodedURLParameterString;

typedef NSUInteger SVHTTPRequestState;

static NSUInteger taskCount = 0;
static NSInteger SVHTTPRequestTaskCount = 0;
static NSString *defaultUserAgent;
static NSTimeInterval SVHTTPRequestTimeoutInterval = 20;

Expand Down Expand Up @@ -103,20 +103,20 @@ - (NSUInteger)timeoutInterval {
return _timeoutInterval;
}

- (void)increaseTaskCount {
taskCount++;
- (void)increaseSVHTTPRequestTaskCount {
SVHTTPRequestTaskCount++;
[self toggleNetworkActivityIndicator];
}

- (void)decreaseTaskCount {
taskCount--;
- (void)decreaseSVHTTPRequestTaskCount {
SVHTTPRequestTaskCount = MAX(0, SVHTTPRequestTaskCount-1);
[self toggleNetworkActivityIndicator];
}

- (void)toggleNetworkActivityIndicator {
#if TARGET_OS_IPHONE
dispatch_async(dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:(taskCount > 0)];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:(SVHTTPRequestTaskCount > 0)];
});
#endif
}
Expand Down Expand Up @@ -351,7 +351,7 @@ - (void)start {
#endif

dispatch_async(dispatch_get_main_queue(), ^{
[self increaseTaskCount];
[self increaseSVHTTPRequestTaskCount];
});

if(self.operationParameters)
Expand Down Expand Up @@ -405,7 +405,7 @@ - (void)finish {
[self.operationConnection cancel];
self.operationConnection = nil;

[self decreaseTaskCount];
[self decreaseSVHTTPRequestTaskCount];

#if TARGET_OS_IPHONE
if(self.backgroundTaskIdentifier != UIBackgroundTaskInvalid) {
Expand Down

0 comments on commit 98ccae4

Please sign in to comment.