diff options
author | Muxi Yan <mxyan@google.com> | 2018-12-06 12:08:43 -0800 |
---|---|---|
committer | Muxi Yan <mxyan@google.com> | 2018-12-06 12:08:43 -0800 |
commit | 70f34521deaeaf0d783f30d121fd26787135ac04 (patch) | |
tree | 5a15946876af9976c3f5214c674a436c6564b5f4 /src/objective-c/ProtoRPC/ProtoRPC.m | |
parent | dfec57a9a9ebfbe92709498074eb184527ef599e (diff) |
isolate start: function from proto calls
Diffstat (limited to 'src/objective-c/ProtoRPC/ProtoRPC.m')
-rw-r--r-- | src/objective-c/ProtoRPC/ProtoRPC.m | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/objective-c/ProtoRPC/ProtoRPC.m b/src/objective-c/ProtoRPC/ProtoRPC.m index 1db04894d5..09f8d03af6 100644 --- a/src/objective-c/ProtoRPC/ProtoRPC.m +++ b/src/objective-c/ProtoRPC/ProtoRPC.m @@ -47,6 +47,7 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing @implementation GRPCUnaryProtoCall { GRPCStreamingProtoCall *_call; + GPBMessage *_message; } - (instancetype)initWithRequestOptions:(GRPCRequestOptions *)requestOptions @@ -54,17 +55,24 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing responseHandler:(id<GRPCProtoResponseHandler>)handler callOptions:(GRPCCallOptions *)callOptions responseClass:(Class)responseClass { + NSAssert(message != nil, @"message cannot be empty."); + NSAssert(responseClass != nil, @"responseClass cannot be empty."); if ((self = [super init])) { _call = [[GRPCStreamingProtoCall alloc] initWithRequestOptions:requestOptions responseHandler:handler callOptions:callOptions responseClass:responseClass]; - [_call writeMessage:message]; - [_call finish]; + _message = [message copy]; } return self; } +- (void)start { + [_call start]; + [_call writeMessage:_message]; + [_call finish]; +} + - (void)cancel { [_call cancel]; _call = nil; @@ -120,15 +128,14 @@ static NSError *ErrorForBadProto(id proto, Class expectedClass, NSError *parsing } dispatch_set_target_queue(_dispatchQueue, handler.dispatchQueue); - [self start]; + _call = [[GRPCCall2 alloc] initWithRequestOptions:_requestOptions + responseHandler:self + callOptions:_callOptions]; } return self; } - (void)start { - _call = [[GRPCCall2 alloc] initWithRequestOptions:_requestOptions - responseHandler:self - callOptions:_callOptions]; [_call start]; } |