Commit 09579dce by Dima Bart

Convert dispatch_queue_t to NSOperationQueue for callbacks.

parent 49f07aff
...@@ -1303,7 +1303,7 @@ ...@@ -1303,7 +1303,7 @@
NSString *apiKey = [self shouldUseMocks] ? BUYAPIKey_Placeholder : self.apiKey; NSString *apiKey = [self shouldUseMocks] ? BUYAPIKey_Placeholder : self.apiKey;
NSString *appId = [self shouldUseMocks] ? BUYAppId_Placeholder : self.appId; NSString *appId = [self shouldUseMocks] ? BUYAppId_Placeholder : self.appId;
BUYClient *testClient = [[BUYClient alloc] initWithShopDomain:shopDomain apiKey:apiKey appId:appId]; BUYClient *testClient = [[BUYClient alloc] initWithShopDomain:shopDomain apiKey:apiKey appId:appId];
testClient.queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0); testClient.callbackQueue = [NSOperationQueue new];
[testClient getShop:^(BUYShop *shop, NSError *error) { [testClient getShop:^(BUYShop *shop, NSError *error) {
BOOL isMainThread = [NSThread isMainThread]; BOOL isMainThread = [NSThread isMainThread];
......
...@@ -95,15 +95,14 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -95,15 +95,14 @@ NS_ASSUME_NONNULL_BEGIN
@property (nonatomic, strong, nonnull) BUYModelManager *modelManager; @property (nonatomic, strong, nonnull) BUYModelManager *modelManager;
/** /**
* Queue where on which all request operation are executed * Queue on which all request operation are executed
*/ */
@property (nonatomic, strong, readonly, nonnull) NSOperationQueue *requestQueue; @property (nonatomic, strong, readonly, nonnull) NSOperationQueue *requestQueue;
/** /**
* Queue where callbacks will be called * Queue on which network completion callbacks will be executed
* defaults to main queue
*/ */
@property (nonatomic, strong, nonnull) dispatch_queue_t queue; @property (nonatomic, strong, nonnull) NSOperationQueue *callbackQueue;
/** /**
* The page size for any paged request. This can range from 1-250. Default is 25 * The page size for any paged request. This can range from 1-250. Default is 25
......
...@@ -58,7 +58,7 @@ static NSString * const BUYClientJSONMimeType = @"application/json"; ...@@ -58,7 +58,7 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
_apiKey = apiKey; _apiKey = apiKey;
_appId = appId; _appId = appId;
_applicationName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"] ?: @""; _applicationName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"] ?: @"";
_queue = dispatch_get_main_queue(); _callbackQueue = [NSOperationQueue mainQueue];
_requestQueue = [NSOperationQueue new]; _requestQueue = [NSOperationQueue new];
_session = [self urlSession]; _session = [self urlSession];
_pageSize = 25; _pageSize = 25;
...@@ -174,9 +174,9 @@ static NSString * const BUYClientJSONMimeType = @"application/json"; ...@@ -174,9 +174,9 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
request.HTTPMethod = method; request.HTTPMethod = method;
BUYRequestOperation *operation = [[BUYRequestOperation alloc] initWithSession:self.session request:request payload:object completion:^(NSDictionary *json, NSURLResponse *response, NSError *error) { BUYRequestOperation *operation = [[BUYRequestOperation alloc] initWithSession:self.session request:request payload:object completion:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
dispatch_async(self.queue, ^{ [self.callbackQueue addOperationWithBlock:^{
completionHandler(json, response, error); completionHandler(json, response, error);
}); }];
}]; }];
[self startTask:operation]; [self startTask:operation];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment