Permalink
Browse files

Change callback queue

  • Loading branch information...
1 parent c80cdc4 commit d60af95dac62310f7c1dab3dce3993b2e08d8ab3 @GlennChiu committed Nov 11, 2012
Showing with 45 additions and 95 deletions.
  1. +18 −38 GCImageRequestOperation.m
  2. +9 −19 GCJSONRequestOperation.m
  3. +18 −38 GCXMLRequestOperation.m
View
@@ -42,38 +42,28 @@ + (GCImageRequestOperation *)imageRequest:(GCNetworkRequest *)networkRequest cal
__block GCImageRequestOperation *operation = nil;
operation = [[GCImageRequestOperation alloc] initWithHTTPRequest:networkRequest
- callBackQueue:queue
+ callBackQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul)
completionHandler:^(NSData *data, NSHTTPURLResponse *response) {
if (completionBlock)
{
- dispatch_block_t block = ^{
-
- UIImage *image = [UIImage imageWithData:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(image, response);});
-
- operation = nil;
- };
+ UIImage *image = [UIImage imageWithData:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(image, response);});
};
+ operation = nil;
+
} errorHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
if (errorBlock)
{
- dispatch_block_t block = ^{
-
- UIImage *image = [UIImage imageWithData:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(image, response, error);});
-
- operation = nil;
- };
+ UIImage *image = [UIImage imageWithData:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(image, response, error);});
};
+
+ operation = nil;
}];
return operation;
}
@@ -85,38 +75,28 @@ + (GCImageRequestOperation *)imageRequest:(GCNetworkRequest *)networkRequest cal
__block GCImageRequestOperation *operation = nil;
operation = [[GCImageRequestOperation alloc] initWithHTTPRequest:networkRequest
- callBackQueue:queue
+ callBackQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul)
completionHandler:^(NSData *data, NSHTTPURLResponse *response) {
if (completionBlock)
{
- dispatch_block_t block = ^{
-
- NSImage *image = [[NSImage alloc] initWithData:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(image, response);});
-
- operation = nil;
- };
+ NSImage *image = [[NSImage alloc] initWithData:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(image, response);});
};
+ operation = nil;
+
} errorHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
if (errorBlock)
{
- dispatch_block_t block = ^{
-
- NSImage *image = [[NSImage alloc] initWithData:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(image, response, error);});
-
- operation = nil;
- };
+ NSImage *image = [[NSImage alloc] initWithData:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(image, response, error);});
};
+
+ operation = nil;
}];
return operation;
}
View
@@ -44,38 +44,28 @@ + (GCJSONRequestOperation *)JSONRequest:(GCNetworkRequest *)networkRequest callB
__block GCJSONRequestOperation *operation = nil;
operation = [[GCJSONRequestOperation alloc] initWithHTTPRequest:networkRequest
- callBackQueue:queue
+ callBackQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul)
completionHandler:^(NSData *data, NSHTTPURLResponse *response) {
if (completionBlock)
{
- dispatch_block_t block = ^{
-
- id JSONObject = [operation processJSON:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(JSONObject, response);});
-
- operation = nil;
- };
+ id JSONObject = [operation processJSON:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(JSONObject, response);});
}
+ operation = nil;
+
} errorHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
if (errorBlock)
{
- dispatch_block_t block = ^{
-
- id JSONObject = [operation processJSON:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(JSONObject, response, [operation error]);});
-
- operation = nil;
- };
+ id JSONObject = [operation processJSON:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(JSONObject, response, [operation error]);});
}
+
+ operation = nil;
}];
return operation;
}
View
@@ -45,38 +45,28 @@ + (GCXMLRequestOperation *)XMLParserRequest:(GCNetworkRequest *)networkRequest c
__block GCXMLRequestOperation *operation = nil;
operation = [[GCXMLRequestOperation alloc] initWithHTTPRequest:networkRequest
- callBackQueue:queue
+ callBackQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul)
completionHandler:^(NSData *data, NSHTTPURLResponse *response) {
if (completionBlock)
{
- dispatch_block_t block = ^{
-
- NSXMLParser *parser = [operation XMLParserFromData:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(parser, response);});
-
- operation = nil;
- };
+ NSXMLParser *parser = [operation XMLParserFromData:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(parser, response);});
}
+ operation = nil;
+
} errorHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
if (errorBlock)
{
- dispatch_block_t block = ^{
-
- NSXMLParser *parser = [operation XMLParserFromData:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(parser, response, error);});
-
- operation = nil;
- };
+ NSXMLParser *parser = [operation XMLParserFromData:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(parser, response, error);});
}
+
+ operation = nil;
}];
return operation;
}
@@ -93,38 +83,28 @@ + (GCXMLRequestOperation *)XMLDocumentRequest:(GCNetworkRequest *)networkRequest
__block GCXMLRequestOperation *operation = nil;
operation = [[GCXMLRequestOperation alloc] initWithHTTPRequest:networkRequest
- callBackQueue:queue
+ callBackQueue:dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul)
completionHandler:^(NSData *data, NSHTTPURLResponse *response) {
if (completionBlock)
{
- dispatch_block_t block = ^{
-
- NSXMLDocument *document = [operation XMLDocumentFromData:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(document, response);});
-
- operation = nil;
- };
+ NSXMLDocument *document = [operation XMLDocumentFromData:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{completionBlock(document, response);});
}
+ operation = nil;
+
} errorHandler:^(NSData *data, NSHTTPURLResponse *response, NSError *error) {
if (errorBlock)
{
- dispatch_block_t block = ^{
-
- NSXMLDocument *document = [operation XMLDocumentFromData:data];
-
- dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(document, response, [operation error]);});
-
- operation = nil;
- };
+ NSXMLDocument *document = [operation XMLDocumentFromData:data];
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0ul), block);
+ dispatch_async(gc_dispatch_queue(queue), ^{errorBlock(document, response, [operation error]);});
}
+
+ operation = nil;
}];
return operation;
}

0 comments on commit d60af95

Please sign in to comment.