Skip to content
This repository has been archived by the owner on Mar 4, 2020. It is now read-only.

Allow us to set the Queue length #399

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions MKNetworkKit/MKNetworkEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,20 @@
- (MKNetworkOperation*)imageAtURL:(NSURL *)url size:(CGSize) size completionHandler:(MKNKImageBlock) imageFetchedBlock errorHandler:(MKNKResponseErrorBlock) errorBlock;
#endif

/*!
* @abstract Set the max allowed network operations in the main queue
*
*/
-(void) setMaxConcurrentOperationCount:(int) ops;

/*!
* @abstract RESET the max allowed network operations in the main queue to defaults
* based on reachability
*
*/
-(void) resetMaxConcurrentOperationCount;


/*!
* @abstract Enqueues your operation into the shared queue
*
Expand Down
23 changes: 23 additions & 0 deletions MKNetworkKit/MKNetworkEngine.m
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,28 @@ -(void) reachabilityChanged:(NSNotification*) notification
}
}


-(void) setMaxConcurrentOperationCount:(int) ops
{
if(ops != [_sharedNetworkQueue maxConcurrentOperationCount]){
[_sharedNetworkQueue setMaxConcurrentOperationCount:ops];
}
}

-(void) resetMaxConcurrentOperationCount
{
if([self.reachability currentReachabilityStatus] == ReachableViaWiFi)
{
[_sharedNetworkQueue setMaxConcurrentOperationCount:6];
}
else if([self.reachability currentReachabilityStatus] == ReachableViaWWAN)
{
[_sharedNetworkQueue setMaxConcurrentOperationCount:2];
}
}



#pragma mark Freezing operations (Called when network connectivity fails)
-(void) freezeOperations {

Expand Down Expand Up @@ -425,6 +447,7 @@ -(NSData*) cachedDataForOperation:(MKNetworkOperation*) operation {
return nil;
}


-(void) enqueueOperation:(MKNetworkOperation*) operation {

[self enqueueOperation:operation forceReload:NO];
Expand Down