GRPC Objective-C  1.73.0
Instance Methods | Class Methods | Properties
GRXWriter Class Reference

An GRXWriter object can produce, on demand, a sequence of values. More...

#import <GRXWriter.h>

Instance Methods

(void) - startWithWriteable:
 Transition to the Started state, and start sending messages to the writeable (a reference to it is retained). More...
 
(void) - finishWithError:
 Send writesFinishedWithError:errorOrNil to the writeable. More...
 
(GRXWriter *) - map:
 Returns a writer that wraps the receiver, and has all the values the receiver would write transformed by the provided mapping function. More...
 

Class Methods

(instancetype) + writerWithEnumerator:
 Returns a writer that pulls values from the passed NSEnumerator instance and pushes them to its writeable. More...
 
(instancetype) + writerWithValueSupplier:
 Returns a writer that pushes to its writeable the successive values returned by the passed block. More...
 
(instancetype) + writerWithContainer:
 Returns a writer that iterates over the values of the passed container and pushes them to its writeable. More...
 
(instancetype) + writerWithValue:
 Returns a writer that sends the passed value to its writeable and then finishes (releasing the value). More...
 
(instancetype) + writerWithError:
 Returns a writer that, as part of its start method, sends the passed error to the writeable (then releasing the error). More...
 
(instancetype) + emptyWriter
 Returns a writer that, as part of its start method, finishes immediately without sending any values to its writeable. More...
 

Properties

GRXWriterState state
 This property can be used to query the current state of the writer, which determines how it might currently use its writeable. More...
 

Detailed Description

An GRXWriter object can produce, on demand, a sequence of values.

The sequence may be produced asynchronously, and it may consist of any number of elements, including none or an infinite number.

GRXWriter is the active dual of NSEnumerator. The difference between them is thus whether the object plays an active or passive role during usage: A user of NSEnumerator pulls values off it, and passes the values to a writeable. A user of GRXWriter, though, just gives it a writeable, and the GRXWriter instance pushes values to the writeable. This makes this protocol suitable to represent a sequence of future values, as well as collections with internal iteration.

An instance of GRXWriter can start producing values after a writeable is passed to it. It can also be commanded to finish the sequence immediately (with an optional error). Finally, it can be asked to pause, and resumed later. All GRXWriter objects support pausing and early termination.

Thread-safety:

State transitions take immediate effect if the object is used from a single thread. Subclasses might offer stronger guarantees.

Unless otherwise indicated by a conforming subclass, no messages should be sent concurrently to a GRXWriter. I.e., conforming classes aren't required to be thread-safe.

Method Documentation

◆ emptyWriter

+ (instancetype) emptyWriter

Returns a writer that, as part of its start method, finishes immediately without sending any values to its writeable.

Implemented in GRXImmediateWriter.

Provided by category GRXWriter(Immediate).

◆ finishWithError:

- (void) finishWithError: (NSError *)  errorOrNil

Send writesFinishedWithError:errorOrNil to the writeable.

Then release the reference to it and transition to the Finished state.

This method might only be called on writers in the Started or Paused state.

◆ map:

- (GRXWriter *) map: (id(^)(id value))  map

Returns a writer that wraps the receiver, and has all the values the receiver would write transformed by the provided mapping function.

Provided by category GRXWriter(Transformations).

◆ startWithWriteable:

- (void) startWithWriteable: (id< GRXWriteable >)  writeable

Transition to the Started state, and start sending messages to the writeable (a reference to it is retained).

Messages to the writeable may be sent before the method returns, or they may be sent later in the future. See GRXWriteable.h for the different messages a writeable can receive.

If this writer draws its values from an external source (e.g. from the filesystem or from a server), calling this method will commonly trigger side effects (like network connections).

This method might only be called on writers in the NotStarted state.

◆ writerWithContainer:

+ (instancetype) writerWithContainer: (id< NSFastEnumeration >)  container

Returns a writer that iterates over the values of the passed container and pushes them to its writeable.

The container is released when the iteration is over.

Note that the usual speed gain of NSFastEnumeration over NSEnumerator results from not having to call one method per element. Because GRXWriteable instances accept values one by one, that speed gain doesn't happen here.

Implemented in GRXImmediateWriter.

Provided by category GRXWriter(Immediate).

◆ writerWithEnumerator:

+ (instancetype) writerWithEnumerator: (NSEnumerator *)  enumerator

Returns a writer that pulls values from the passed NSEnumerator instance and pushes them to its writeable.

The NSEnumerator is released when it finishes.

Implemented in GRXImmediateWriter.

Provided by category GRXWriter(Immediate).

◆ writerWithError:

+ (instancetype) writerWithError: (NSError *)  error

Returns a writer that, as part of its start method, sends the passed error to the writeable (then releasing the error).

Implemented in GRXImmediateWriter.

Provided by category GRXWriter(Immediate).

◆ writerWithValue:

+ (instancetype) writerWithValue: (id)  value

Returns a writer that sends the passed value to its writeable and then finishes (releasing the value).

Implemented in GRXImmediateSingleWriter, and GRXImmediateWriter.

Provided by category GRXWriter(Immediate).

◆ writerWithValueSupplier:

+ (instancetype) writerWithValueSupplier: (id(^)(void))  block

Returns a writer that pushes to its writeable the successive values returned by the passed block.

When the block first returns nil, it is released.

Implemented in GRXImmediateWriter.

Provided by category GRXWriter(Immediate).

Property Documentation

◆ state

- (GRXWriterState) state
readwriteatomic

This property can be used to query the current state of the writer, which determines how it might currently use its writeable.

Some state transitions can be triggered by setting this property to the corresponding value, and that's useful for advanced use cases like pausing an writer. For more details, see the documentation of the enum further down. The property is thread safe.


The documentation for this class was generated from the following file: