Addressed the comments

pull/9247/head
Muxi Yan 8 years ago
parent 9f74e838e2
commit c2e53b5af4
  1. 5
      src/objective-c/GRPCClient/GRPCCall.m
  2. 5
      src/objective-c/GRPCClient/private/GRPCOpBatchLog.h
  3. 10
      src/objective-c/GRPCClient/private/GRPCOpBatchLog.m
  4. 15
      src/objective-c/RxLibrary/GRXImmediateSingleWriter.m

@ -107,8 +107,11 @@ static NSMutableDictionary *callFlags;
GRPCRequestHeaders *_requestHeaders; GRPCRequestHeaders *_requestHeaders;
// In the case that the call is a unary call (i.e. the writer to GRPCCall is of type
// GRXImmediateSingleWriter), GRPCCall will delay sending ops (not send them to C core
// immediately) and buffer them into a batch _unaryOpBatch. The batch is sent to C core when
// the SendClose op is added.
BOOL _unaryCall; BOOL _unaryCall;
NSMutableArray *_unaryOpBatch; NSMutableArray *_unaryOpBatch;
} }

@ -31,6 +31,9 @@
* *
*/ */
#ifdef GRPC_TEST_OBJC
/** /**
* Logs the op batches of a client. Used for testing. * Logs the op batches of a client. Used for testing.
*/ */
@ -52,3 +55,5 @@
+ (NSArray *)obtainAndCleanOpBatchLog; + (NSArray *)obtainAndCleanOpBatchLog;
@end @end
#endif

@ -31,11 +31,13 @@
* *
*/ */
#ifdef GRPC_TEST_OBJC
#import "GRPCOpBatchLog.h" #import "GRPCOpBatchLog.h"
@implementation GRPCOpBatchLog static NSMutableArray *opBatchLog = nil;
NSMutableArray *opBatchLog = nil; @implementation GRPCOpBatchLog
+ (void)enableOpBatchLog:(BOOL)enabled { + (void)enableOpBatchLog:(BOOL)enabled {
@synchronized (opBatchLog) { @synchronized (opBatchLog) {
@ -65,4 +67,6 @@ NSMutableArray *opBatchLog = nil;
} }
} }
@end @end
#endif

@ -35,41 +35,40 @@
@implementation GRXImmediateSingleWriter { @implementation GRXImmediateSingleWriter {
id _value; id _value;
NSError *_errorOrNil;
id<GRXWriteable> _writeable; id<GRXWriteable> _writeable;
} }
@synthesize state = _state; @synthesize state = _state;
- (instancetype)initWithValue:(id)value error:(NSError *)errorOrNil { - (instancetype)initWithValue:(id)value {
if (self = [super init]) { if (self = [super init]) {
_value = value; _value = value;
_errorOrNil = errorOrNil;
_state = GRXWriterStateNotStarted; _state = GRXWriterStateNotStarted;
} }
return self; return self;
} }
+ (GRXWriter *)writerWithValue:(id)value { + (GRXWriter *)writerWithValue:(id)value {
return [[self alloc] initWithValue:value error:nil]; return [[self alloc] initWithValue:value];
} }
- (void)startWithWriteable:(id<GRXWriteable>)writeable { - (void)startWithWriteable:(id<GRXWriteable>)writeable {
_state = GRXWriterStateStarted; _state = GRXWriterStateStarted;
_writeable = writeable; _writeable = writeable;
[writeable writeValue:_value]; [writeable writeValue:_value];
[self finishWithError:_errorOrNil]; [self finish];
} }
- (void)finishWithError:(NSError *)errorOrNil { - (void)finish {
_state = GRXWriterStateFinished; _state = GRXWriterStateFinished;
_errorOrNil = nil;
_value = nil; _value = nil;
id<GRXWriteable> writeable = _writeable; id<GRXWriteable> writeable = _writeable;
_writeable = nil; _writeable = nil;
[writeable writesFinishedWithError:errorOrNil]; [writeable writesFinishedWithError:nil];
} }
// Overwrite the setter to disallow manual state transition. The getter
// of _state is synthesized.
- (void)setState:(GRXWriterState)newState { - (void)setState:(GRXWriterState)newState {
// Manual state transition is not allowed // Manual state transition is not allowed
return; return;

Loading…
Cancel
Save