Check if optional method of GRPCCallOptions are implemented

pull/16190/head
Muxi Yan 6 years ago
parent 413077101e
commit f18b08a1a4
  1. 2
      src/objective-c/GRPCClient/GRPCCall.h
  2. 10
      src/objective-c/GRPCClient/GRPCCall.m

@ -149,7 +149,7 @@ extern id const kGRPCHeadersKey;
extern id const kGRPCTrailersKey; extern id const kGRPCTrailersKey;
/** An object can implement this protocol to receive responses from server from a call. */ /** An object can implement this protocol to receive responses from server from a call. */
@protocol GRPCResponseHandler @protocol GRPCResponseHandler <NSObject>
@optional @optional

@ -149,12 +149,16 @@ const char *kCFStreamVarName = "grpc_cfstream";
} }
if (headers) { if (headers) {
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
if ([handler respondsToSelector:@selector(receivedInitialMetadata:)]) {
[handler receivedInitialMetadata:headers]; [handler receivedInitialMetadata:headers];
}
}); });
} }
if (value) { if (value) {
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
if ([handler respondsToSelector:@selector(receivedMessage:)]) {
[handler receivedMessage:value]; [handler receivedMessage:value];
}
}); });
} }
} }
@ -171,11 +175,15 @@ const char *kCFStreamVarName = "grpc_cfstream";
} }
if (headers) { if (headers) {
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
if ([handler respondsToSelector:@selector(receivedInitialMetadata:)]) {
[handler receivedInitialMetadata:headers]; [handler receivedInitialMetadata:headers];
}
}); });
} }
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
[handler closedWithTrailingMetadata:self->_call.responseTrailers error:errorOrNil]; [handler closedWithTrailingMetadata:self->_call.responseTrailers error:errorOrNil];
}
}); });
} }
}); });
@ -193,6 +201,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
if (self->_handler) { if (self->_handler) {
id<GRPCResponseHandler> handler = self->_handler; id<GRPCResponseHandler> handler = self->_handler;
dispatch_async(handler.dispatchQueue, ^{ dispatch_async(handler.dispatchQueue, ^{
if ([handler respondsToSelector:@selector(closedWithTrailingMetadata:error:)]) {
[handler closedWithTrailingMetadata:nil [handler closedWithTrailingMetadata:nil
error:[NSError errorWithDomain:kGRPCErrorDomain error:[NSError errorWithDomain:kGRPCErrorDomain
code:GRPCErrorCodeCancelled code:GRPCErrorCodeCancelled
@ -200,6 +209,7 @@ const char *kCFStreamVarName = "grpc_cfstream";
NSLocalizedDescriptionKey : NSLocalizedDescriptionKey :
@"Canceled by app" @"Canceled by app"
}]]; }]];
}
}); });
self->_handler = nil; self->_handler = nil;
} }

Loading…
Cancel
Save