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. 32
      src/objective-c/GRPCClient/GRPCCall.m

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

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

Loading…
Cancel
Save