Merge pull request #1664 from jcanizales/renames-grx-writeable-methods

Rename GRXWriteable methods
pull/1676/head
Michael Lumish 10 years ago
commit 958b0b9e7a
  1. 6
      src/objective-c/GRPCClient/GRPCCall.m
  2. 17
      src/objective-c/GRPCClient/private/GRPCDelegateWrapper.h
  3. 8
      src/objective-c/GRPCClient/private/GRPCDelegateWrapper.m
  4. 4
      src/objective-c/ProtoRPC/ProtoRPC.m
  5. 6
      src/objective-c/RxLibrary/GRXBufferedPipe.h
  6. 10
      src/objective-c/RxLibrary/GRXBufferedPipe.m
  7. 4
      src/objective-c/RxLibrary/GRXImmediateWriter.m
  8. 8
      src/objective-c/RxLibrary/GRXWriteable.h
  9. 4
      src/objective-c/RxLibrary/GRXWriteable.m
  10. 6
      src/objective-c/RxLibrary/GRXWriter.h
  11. 8
      src/objective-c/RxLibrary/GRXWriter.m
  12. 4
      src/objective-c/RxLibrary/transformations/GRXMappingWriter.m
  13. 6
      src/objective-c/examples/Sample/SampleTests/RemoteProtoTests.m

@ -231,7 +231,7 @@
handler:resumingHandler]] errorHandler:errorHandler]; handler:resumingHandler]] errorHandler:errorHandler];
} }
- (void)didReceiveValue:(id)value { - (void)writeValue:(id)value {
// TODO(jcanizales): Throw/assert if value isn't NSData. // TODO(jcanizales): Throw/assert if value isn't NSData.
// Pause the input and only resume it when the C layer notifies us that writes // Pause the input and only resume it when the C layer notifies us that writes
@ -255,7 +255,7 @@
errorHandler:errorHandler]; errorHandler:errorHandler];
} }
- (void)didFinishWithError:(NSError *)errorOrNil { - (void)writesFinishedWithError:(NSError *)errorOrNil {
if (errorOrNil) { if (errorOrNil) {
[self cancel]; [self cancel];
} else { } else {
@ -306,7 +306,7 @@
- (void)startWithWriteable:(id<GRXWriteable>)writeable { - (void)startWithWriteable:(id<GRXWriteable>)writeable {
// The following produces a retain cycle self:_responseWriteable:self, which is only // The following produces a retain cycle self:_responseWriteable:self, which is only
// broken when didFinishWithError: is sent to the wrapped writeable. // broken when writesFinishedWithError: is sent to the wrapped writeable.
// Care is taken not to retain self strongly in any of the blocks used in // Care is taken not to retain self strongly in any of the blocks used in
// the implementation of GRPCCall, so that the life of the instance is // the implementation of GRPCCall, so that the life of the instance is
// determined by this retain cycle. // determined by this retain cycle.

@ -38,11 +38,11 @@
// This is a thread-safe wrapper over a GRXWriteable instance. It lets one // This is a thread-safe wrapper over a GRXWriteable instance. It lets one
// enqueue calls to a GRXWriteable instance for the main thread, guaranteeing // enqueue calls to a GRXWriteable instance for the main thread, guaranteeing
// that didFinishWithError: is the last message sent to it (no matter what // that writesFinishedWithError: is the last message sent to it (no matter what
// messages are sent to the wrapper, in what order, nor from which thread). It // messages are sent to the wrapper, in what order, nor from which thread). It
// also guarantees that, if cancelWithError: is called from the main thread // also guarantees that, if cancelWithError: is called from the main thread
// (e.g. by the app cancelling the writes), no further messages are sent to the // (e.g. by the app cancelling the writes), no further messages are sent to the
// writeable except didFinishWithError:. // writeable except writesFinishedWithError:.
// //
// TODO(jcanizales): Let the user specify another queue for the writeable // TODO(jcanizales): Let the user specify another queue for the writeable
// callbacks. // callbacks.
@ -51,23 +51,22 @@
// The GRXWriteable passed is the wrapped writeable. // The GRXWriteable passed is the wrapped writeable.
// Both the GRXWriter instance and the GRXWriteable instance are retained until // Both the GRXWriter instance and the GRXWriteable instance are retained until
// didFinishWithError: is sent to the writeable, and released after that. // writesFinishedWithError: is sent to the writeable, and released after that.
// This is used to create a retain cycle that keeps both objects alive until the // This is used to create a retain cycle that keeps both objects alive until the
// writing is explicitly finished. // writing is explicitly finished.
- (instancetype)initWithWriteable:(id<GRXWriteable>)writeable writer:(id<GRXWriter>)writer - (instancetype)initWithWriteable:(id<GRXWriteable>)writeable writer:(id<GRXWriter>)writer
NS_DESIGNATED_INITIALIZER; NS_DESIGNATED_INITIALIZER;
// Enqueues didReceiveValue: to be sent to the writeable in the main thread. // Enqueues writeValue: to be sent to the writeable in the main thread.
// The passed handler is invoked from the main thread after didReceiveValue: // The passed handler is invoked from the main thread after writeValue: returns.
// returns.
- (void)enqueueMessage:(NSData *)message completionHandler:(void (^)())handler; - (void)enqueueMessage:(NSData *)message completionHandler:(void (^)())handler;
// Enqueues didFinishWithError:nil to be sent to the writeable in the main // Enqueues writesFinishedWithError:nil to be sent to the writeable in the main
// thread. After that message is sent to the writeable, all other methods of // thread. After that message is sent to the writeable, all other methods of
// this object are effectively noops. // this object are effectively noops.
- (void)enqueueSuccessfulCompletion; - (void)enqueueSuccessfulCompletion;
// If the writeable has not yet received a didFinishWithError: message, this // If the writeable has not yet received a writesFinishedWithError: message, this
// will enqueue one to be sent to it in the main thread, and cancel all other // will enqueue one to be sent to it in the main thread, and cancel all other
// pending messages to the writeable enqueued by this object (both past and // pending messages to the writeable enqueued by this object (both past and
// future). // future).
@ -75,7 +74,7 @@
- (void)cancelWithError:(NSError *)error; - (void)cancelWithError:(NSError *)error;
// Cancels all pending messages to the writeable enqueued by this object (both // Cancels all pending messages to the writeable enqueued by this object (both
// past and future). Because the writeable won't receive didFinishWithError:, // past and future). Because the writeable won't receive writesFinishedWithError:,
// this also releases the writeable and the writer. // this also releases the writeable and the writer.
- (void)cancelSilently; - (void)cancelSilently;
@end @end

@ -43,7 +43,7 @@
@implementation GRPCDelegateWrapper { @implementation GRPCDelegateWrapper {
dispatch_queue_t _writeableQueue; dispatch_queue_t _writeableQueue;
// This ensures that didFinishWithError: is only sent once to the writeable. // This ensures that writesFinishedWithError: is only sent once to the writeable.
dispatch_once_t _alreadyFinished; dispatch_once_t _alreadyFinished;
} }
@ -69,7 +69,7 @@
// the race. // the race.
id<GRXWriteable> writeable = self.writeable; id<GRXWriteable> writeable = self.writeable;
if (writeable) { if (writeable) {
[writeable didReceiveValue:message]; [writeable writeValue:message];
handler(); handler();
} }
}); });
@ -80,7 +80,7 @@
dispatch_once(&_alreadyFinished, ^{ dispatch_once(&_alreadyFinished, ^{
// Cancellation is now impossible. None of the other three blocks can run // Cancellation is now impossible. None of the other three blocks can run
// concurrently with this one. // concurrently with this one.
[self.writeable didFinishWithError:nil]; [self.writeable writesFinishedWithError:nil];
// Break the retain cycle with writer, and skip any possible message to the // Break the retain cycle with writer, and skip any possible message to the
// wrapped writeable enqueued after this one. // wrapped writeable enqueued after this one.
self.writeable = nil; self.writeable = nil;
@ -100,7 +100,7 @@
self.writeable = nil; self.writeable = nil;
dispatch_async(_writeableQueue, ^{ dispatch_async(_writeableQueue, ^{
[writeable didFinishWithError:error]; [writeable writesFinishedWithError:error];
// Break the retain cycle with writer. // Break the retain cycle with writer.
self.writer = nil; self.writer = nil;
}); });

@ -71,9 +71,9 @@
if ((self = [super initWithHost:host method:method requestsWriter:bytesWriter])) { if ((self = [super initWithHost:host method:method requestsWriter:bytesWriter])) {
// A writeable that parses the proto messages received. // A writeable that parses the proto messages received.
_responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) { _responseWriteable = [[GRXWriteable alloc] initWithValueHandler:^(NSData *value) {
[responsesWriteable didReceiveValue:[responseClass parseFromData:value]]; [responsesWriteable writeValue:[responseClass parseFromData:value]];
} completionHandler:^(NSError *errorOrNil) { } completionHandler:^(NSError *errorOrNil) {
[responsesWriteable didFinishWithError:errorOrNil]; [responsesWriteable writesFinishedWithError:errorOrNil];
}]; }];
} }
return self; return self;

@ -38,12 +38,12 @@
// A buffered pipe is a Writeable that also acts as a Writer (to whichever other writeable is passed // A buffered pipe is a Writeable that also acts as a Writer (to whichever other writeable is passed
// to -startWithWriteable:). // to -startWithWriteable:).
// Once it is started, whatever values are written into it (via -didReceiveValue:) will be // Once it is started, whatever values are written into it (via -writeValue:) will be propagated
// propagated immediately, unless flow control prevents it. // immediately, unless flow control prevents it.
// If it is throttled and keeps receiving values, as well as if it receives values before being // If it is throttled and keeps receiving values, as well as if it receives values before being
// started, it will buffer them and propagate them in order as soon as its state becomes // started, it will buffer them and propagate them in order as soon as its state becomes
// GRXWriterStateStarted. // GRXWriterStateStarted.
// If it receives an error (via -didFinishWithError:), it will drop any buffered values and // If it receives an error (via -writesFinishedWithError:), it will drop any buffered values and
// propagate the error immediately. // propagate the error immediately.
// //
// Beware that a pipe of this type can't prevent receiving more values when it is paused (for // Beware that a pipe of this type can't prevent receiving more values when it is paused (for

@ -62,7 +62,7 @@
- (void)writeBufferUntilPausedOrStopped { - (void)writeBufferUntilPausedOrStopped {
while (_state == GRXWriterStateStarted && _queue.count > 0) { while (_state == GRXWriterStateStarted && _queue.count > 0) {
[_writeable didReceiveValue:[self popValue]]; [_writeable writeValue:[self popValue]];
} }
if (_inputIsFinished && _queue.count == 0) { if (_inputIsFinished && _queue.count == 0) {
// Our writer finished normally while we were paused or not-started-yet. // Our writer finished normally while we were paused or not-started-yet.
@ -77,10 +77,10 @@
return _state == GRXWriterStateStarted && _queue.count == 0; return _state == GRXWriterStateStarted && _queue.count == 0;
} }
- (void)didReceiveValue:(id)value { - (void)writeValue:(id)value {
if (self.shouldFastForward) { if (self.shouldFastForward) {
// Skip the queue. // Skip the queue.
[_writeable didReceiveValue:value]; [_writeable writeValue:value];
} else { } else {
// Even if we're paused and with enqueued values, we can't excert back-pressure to our writer. // Even if we're paused and with enqueued values, we can't excert back-pressure to our writer.
// So just buffer the new value. // So just buffer the new value.
@ -92,7 +92,7 @@
} }
} }
- (void)didFinishWithError:(NSError *)errorOrNil { - (void)writesFinishedWithError:(NSError *)errorOrNil {
_inputIsFinished = YES; _inputIsFinished = YES;
_errorOrNil = errorOrNil; _errorOrNil = errorOrNil;
if (errorOrNil || self.shouldFastForward) { if (errorOrNil || self.shouldFastForward) {
@ -140,7 +140,7 @@
- (void)finishWithError:(NSError *)errorOrNil { - (void)finishWithError:(NSError *)errorOrNil {
id<GRXWriteable> writeable = _writeable; id<GRXWriteable> writeable = _writeable;
self.state = GRXWriterStateFinished; self.state = GRXWriterStateFinished;
[writeable didFinishWithError:errorOrNil]; [writeable writesFinishedWithError:errorOrNil];
} }
@end @end

@ -109,7 +109,7 @@
- (void)writeUntilPausedOrStopped { - (void)writeUntilPausedOrStopped {
id value; id value;
while (value = [_enumerator nextObject]) { while (value = [_enumerator nextObject]) {
[_writeable didReceiveValue:value]; [_writeable writeValue:value];
// If the writeable has a reference to us, it might change our state to paused or finished. // If the writeable has a reference to us, it might change our state to paused or finished.
if (_state == GRXWriterStatePaused || _state == GRXWriterStateFinished) { if (_state == GRXWriterStatePaused || _state == GRXWriterStateFinished) {
return; return;
@ -130,7 +130,7 @@
_errorOrNil = nil; _errorOrNil = nil;
id<GRXWriteable> writeable = _writeable; id<GRXWriteable> writeable = _writeable;
_writeable = nil; _writeable = nil;
[writeable didFinishWithError:errorOrNil]; [writeable writesFinishedWithError:errorOrNil];
} }
- (void)setState:(GRXWriterState)newState { - (void)setState:(GRXWriterState)newState {

@ -38,14 +38,12 @@
@protocol GRXWriteable <NSObject> @protocol GRXWriteable <NSObject>
// Push the next value of the sequence to the receiving object. // Push the next value of the sequence to the receiving object.
// TODO(jcanizales): Name it enumerator:(id<GRXEnumerator>) didProduceValue:(id)? - (void)writeValue:(id)value;
- (void)didReceiveValue:(id)value;
// Signal that the sequence is completed, or that an error ocurred. After this // Signal that the sequence is completed, or that an error ocurred. After this
// message is sent to the instance, neither it nor didReceiveValue: may be // message is sent to the instance, neither it nor writeValue: may be
// called again. // called again.
// TODO(jcanizales): enumerator:(id<GRXEnumerator>) didFinishWithError:(NSError*)? - (void)writesFinishedWithError:(NSError *)errorOrNil;
- (void)didFinishWithError:(NSError *)errorOrNil;
@end @end
typedef void (^GRXValueHandler)(id value); typedef void (^GRXValueHandler)(id value);

@ -76,13 +76,13 @@
return self; return self;
} }
- (void)didReceiveValue:(id)value { - (void)writeValue:(id)value {
if (_valueHandler) { if (_valueHandler) {
_valueHandler(value); _valueHandler(value);
} }
} }
- (void)didFinishWithError:(NSError *)errorOrNil { - (void)writesFinishedWithError:(NSError *)errorOrNil {
if (_completionHandler) { if (_completionHandler) {
_completionHandler(errorOrNil); _completionHandler(errorOrNil);
} }

@ -50,7 +50,7 @@ typedef NS_ENUM(NSInteger, GRXWriterState) {
// The writer is temporarily paused, and won't send any more values to the // The writer is temporarily paused, and won't send any more values to the
// writeable unless its state is set back to Started. The writer might still // writeable unless its state is set back to Started. The writer might still
// transition to the Finished state at any moment, and is allowed to send // transition to the Finished state at any moment, and is allowed to send
// didFinishWithError: to its writeable. // writesFinishedWithError: to its writeable.
// //
// Not all implementations of writer have to support pausing, and thus // Not all implementations of writer have to support pausing, and thus
// trying to set an writer's state to this value might have no effect. // trying to set an writer's state to this value might have no effect.
@ -59,7 +59,7 @@ typedef NS_ENUM(NSInteger, GRXWriterState) {
// The writer has released its writeable and won't interact with it anymore. // The writer has released its writeable and won't interact with it anymore.
// //
// One seldomly wants to set an writer's state to this value, as its // One seldomly wants to set an writer's state to this value, as its
// writeable isn't notified with a didFinishWithError: message. Instead, sending // writeable isn't notified with a writesFinishedWithError: message. Instead, sending
// finishWithError: to the writer will make it notify the writeable and then // finishWithError: to the writer will make it notify the writeable and then
// transition to this state. // transition to this state.
GRXWriterStateFinished GRXWriterStateFinished
@ -105,7 +105,7 @@ typedef NS_ENUM(NSInteger, GRXWriterState) {
// This method might only be called on writers in the NotStarted state. // This method might only be called on writers in the NotStarted state.
- (void)startWithWriteable:(id<GRXWriteable>)writeable; - (void)startWithWriteable:(id<GRXWriteable>)writeable;
// Send didFinishWithError:errorOrNil immediately to the writeable, and don't send // Send writesFinishedWithError:errorOrNil immediately to the writeable, and don't send
// any more messages to it. // any more messages to it.
// //
// This method might only be called on writers in the Started or Paused // This method might only be called on writers in the Started or Paused

@ -62,7 +62,7 @@
- (void)finishOutputWithError:(NSError *)errorOrNil { - (void)finishOutputWithError:(NSError *)errorOrNil {
id<GRXWriteable> writeable = _writeable; id<GRXWriteable> writeable = _writeable;
_writeable = nil; _writeable = nil;
[writeable didFinishWithError:errorOrNil]; [writeable writesFinishedWithError:errorOrNil];
} }
// This is used to stop the input writer. It nillifies our reference to it // This is used to stop the input writer. It nillifies our reference to it
@ -75,11 +75,11 @@
#pragma mark GRXWriteable implementation #pragma mark GRXWriteable implementation
- (void)didReceiveValue:(id)value { - (void)writeValue:(id)value {
[_writeable didReceiveValue:value]; [_writeable writeValue:value];
} }
- (void)didFinishWithError:(NSError *)errorOrNil { - (void)writesFinishedWithError:(NSError *)errorOrNil {
_writer = nil; _writer = nil;
[self finishOutputWithError:errorOrNil]; [self finishOutputWithError:errorOrNil];
} }

@ -57,7 +57,7 @@ static id (^kIdentity)(id value) = ^id(id value) {
} }
// Override // Override
- (void)didReceiveValue:(id)value { - (void)writeValue:(id)value {
[super didReceiveValue:_map(value)]; [super writeValue:_map(value)];
} }
@end @end

@ -208,7 +208,7 @@
id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index]
requestedResponseSize:responses[index]]; requestedResponseSize:responses[index]];
[requestsBuffer didReceiveValue:request]; [requestsBuffer writeValue:request];
[_service fullDuplexCallWithRequestsWriter:requestsBuffer [_service fullDuplexCallWithRequestsWriter:requestsBuffer
handler:^(BOOL done, handler:^(BOOL done,
@ -225,9 +225,9 @@
if (index < 4) { if (index < 4) {
id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index] id request = [RMTStreamingOutputCallRequest messageWithPayloadSize:requests[index]
requestedResponseSize:responses[index]]; requestedResponseSize:responses[index]];
[requestsBuffer didReceiveValue:request]; [requestsBuffer writeValue:request];
} else { } else {
[requestsBuffer didFinishWithError:nil]; [requestsBuffer writesFinishedWithError:nil];
} }
} }

Loading…
Cancel
Save