Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use NSOperationQueue (GH-452) #454

Open
wants to merge 2 commits 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
2 changes: 2 additions & 0 deletions CordovaLib/Classes/Public/CDVCommandDelegateImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
@interface CDVCommandDelegateImpl : NSObject <CDVCommandDelegate>{
@private
__weak CDVViewController* _viewController;
@private
NSOperationQueue* _operationQueue;
NSRegularExpression* _callbackIdPattern;
@protected
__weak CDVCommandQueue* _commandQueue;
Expand Down
8 changes: 7 additions & 1 deletion CordovaLib/Classes/Public/CDVCommandDelegateImpl.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Licensed to the Apache Software Foundation (ASF) under one
#import "CDVPluginResult.h"
#import "CDVViewController.h"

static const NSInteger MAX_CONCURRENT_OPERATION = 32; // Half of the GCD limitation.

@implementation CDVCommandDelegateImpl

@synthesize urlTransformer;
Expand All @@ -33,6 +35,10 @@ - (id)initWithViewController:(CDVViewController*)viewController
if (self != nil) {
_viewController = viewController;
_commandQueue = _viewController.commandQueue;
_operationQueue = [[NSOperationQueue alloc] init];
[_operationQueue setQualityOfService:NSQualityOfServiceBackground];
[_operationQueue setMaxConcurrentOperationCount:MAX_CONCURRENT_OPERATION];


NSError* err = nil;
_callbackIdPattern = [NSRegularExpression regularExpressionWithPattern:@"[^A-Za-z0-9._-]" options:0 error:&err];
Expand Down Expand Up @@ -170,7 +176,7 @@ - (id)getCommandInstance:(NSString*)pluginName

- (void)runInBackground:(void (^)(void))block
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), block);
[_operationQueue addOperationWithBlock:block];
}

- (NSString*)userAgent
Expand Down