aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/objective-c/GRPCClient/GRPCCall.m
diff options
context:
space:
mode:
authorGravatar Muxi Yan <mxyan@google.com>2018-11-14 14:09:41 -0800
committerGravatar Muxi Yan <mxyan@google.com>2018-11-14 14:09:41 -0800
commitb77203fdf59faa38e7be01f8796d3bc3e67db602 (patch)
treeab6e341a8e874478f407332b7ac3a117ecc89a29 /src/objective-c/GRPCClient/GRPCCall.m
parent8d0cf9ec0aaa9e9efd23254d189d78fbaead2702 (diff)
Move blocks into varibles for readability
Diffstat (limited to 'src/objective-c/GRPCClient/GRPCCall.m')
-rw-r--r--src/objective-c/GRPCClient/GRPCCall.m53
1 files changed, 28 insertions, 25 deletions
diff --git a/src/objective-c/GRPCClient/GRPCCall.m b/src/objective-c/GRPCClient/GRPCCall.m
index 5e3491dafa..39681d2adf 100644
--- a/src/objective-c/GRPCClient/GRPCCall.m
+++ b/src/objective-c/GRPCClient/GRPCCall.m
@@ -172,7 +172,8 @@ const char *kCFStreamVarName = "grpc_cfstream";
if (self->_callOptions.initialMetadata) {
[self->_call.requestHeaders addEntriesFromDictionary:self->_callOptions.initialMetadata];
}
- id<GRXWriteable> responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(id value) {
+
+ void (^valueHandler)(id value) = ^(id value) {
dispatch_async(self->_dispatchQueue, ^{
if (self->_handler) {
if (!self->_initialMetadataPublished) {
@@ -184,30 +185,32 @@ const char *kCFStreamVarName = "grpc_cfstream";
}
}
});
- }
- completionHandler:^(NSError *errorOrNil) {
- dispatch_async(self->_dispatchQueue, ^{
- if (self->_handler) {
- if (!self->_initialMetadataPublished) {
- self->_initialMetadataPublished = YES;
- [self issueInitialMetadata:self->_call.responseHeaders];
- }
- [self issueClosedWithTrailingMetadata:self->_call.responseTrailers error:errorOrNil];
-
- // Clean up _handler so that no more responses are reported to the handler.
- self->_handler = nil;
- }
- // Clearing _call must happen *after* dispatching close in order to get trailing
- // metadata from _call.
- if (self->_call) {
- // Clean up the request writers. This should have no effect to _call since its
- // response writeable is already nullified.
- [self->_pipe writesFinishedWithError:nil];
- self->_call = nil;
- self->_pipe = nil;
- }
- });
- }];
+ };
+ void (^completionHandler)(NSError *errorOrNil) = ^(NSError *errorOrNil) {
+ dispatch_async(self->_dispatchQueue, ^{
+ if (self->_handler) {
+ if (!self->_initialMetadataPublished) {
+ self->_initialMetadataPublished = YES;
+ [self issueInitialMetadata:self->_call.responseHeaders];
+ }
+ [self issueClosedWithTrailingMetadata:self->_call.responseTrailers error:errorOrNil];
+
+ // Clean up _handler so that no more responses are reported to the handler.
+ self->_handler = nil;
+ }
+ // Clearing _call must happen *after* dispatching close in order to get trailing
+ // metadata from _call.
+ if (self->_call) {
+ // Clean up the request writers. This should have no effect to _call since its
+ // response writeable is already nullified.
+ [self->_pipe writesFinishedWithError:nil];
+ self->_call = nil;
+ self->_pipe = nil;
+ }
+ });
+ };
+ id<GRXWriteable> responseWriteable = [[GRXWriteable alloc] initWithValueHandler:valueHandler
+ completionHandler:completionHandler];
[self->_call startWithWriteable:responseWriteable];
});
}