|
|
@ -35,73 +35,87 @@ |
|
|
|
|
|
|
|
|
|
|
|
#import "GRXWriteable.h" |
|
|
|
#import "GRXWriteable.h" |
|
|
|
|
|
|
|
|
|
|
|
// States of a writer.
|
|
|
|
/** States of a writer. */ |
|
|
|
typedef NS_ENUM(NSInteger, GRXWriterState) { |
|
|
|
typedef NS_ENUM(NSInteger, GRXWriterState) { |
|
|
|
|
|
|
|
|
|
|
|
// The writer has not yet been given a writeable to which it can push its values. To have a writer
|
|
|
|
/**
|
|
|
|
// transition to the Started state, send it a startWithWriteable: message.
|
|
|
|
* The writer has not yet been given a writeable to which it can push its values. To have a writer |
|
|
|
//
|
|
|
|
* transition to the Started state, send it a startWithWriteable: message. |
|
|
|
// A writer's state cannot be manually set to this value.
|
|
|
|
* |
|
|
|
|
|
|
|
* A writer's state cannot be manually set to this value. |
|
|
|
|
|
|
|
*/ |
|
|
|
GRXWriterStateNotStarted, |
|
|
|
GRXWriterStateNotStarted, |
|
|
|
|
|
|
|
|
|
|
|
// The writer might push values to the writeable at any moment.
|
|
|
|
/** The writer might push values to the writeable at any moment. */ |
|
|
|
GRXWriterStateStarted, |
|
|
|
GRXWriterStateStarted, |
|
|
|
|
|
|
|
|
|
|
|
// 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 transition to the Finished state at any
|
|
|
|
* The writer is temporarily paused, and won't send any more values to the writeable unless its |
|
|
|
// moment, and is allowed to send writesFinishedWithError: to its writeable.
|
|
|
|
* state is set back to Started. The writer might still transition to the Finished state at any |
|
|
|
|
|
|
|
* moment, and is allowed to send writesFinishedWithError: to its writeable. |
|
|
|
|
|
|
|
*/ |
|
|
|
GRXWriterStatePaused, |
|
|
|
GRXWriterStatePaused, |
|
|
|
|
|
|
|
|
|
|
|
// 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 a writer's state to this value, as its writeable isn't notified with
|
|
|
|
* |
|
|
|
// a writesFinishedWithError: message. Instead, sending finishWithError: to the writer will make
|
|
|
|
* One seldomly wants to set a writer's state to this value, as its writeable isn't notified with |
|
|
|
// it notify the writeable and then transition to this state.
|
|
|
|
* a writesFinishedWithError: message. Instead, sending finishWithError: to the writer will make |
|
|
|
|
|
|
|
* it notify the writeable and then transition to this state. |
|
|
|
|
|
|
|
*/ |
|
|
|
GRXWriterStateFinished |
|
|
|
GRXWriterStateFinished |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
* An GRXWriter object can produce, on demand, a sequence of values. The sequence may be produced |
|
|
|
// number.
|
|
|
|
* 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,
|
|
|
|
* GRXWriter is the active dual of NSEnumerator. The difference between them is thus whether the |
|
|
|
// and passes the values to a writeable. A user of GRXWriter, though, just gives it a writeable, and
|
|
|
|
* object plays an active or passive role during usage: A user of NSEnumerator pulls values off it, |
|
|
|
// the GRXWriter instance pushes values to the writeable. This makes this protocol suitable to
|
|
|
|
* and passes the values to a writeable. A user of GRXWriter, though, just gives it a writeable, and |
|
|
|
// represent a sequence of future values, as well as collections with internal iteration.
|
|
|
|
* 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
|
|
|
|
* An instance of GRXWriter can start producing values after a writeable is passed to it. It can |
|
|
|
// asked to pause, and resumed later. All GRXWriter objects support pausing and early termination.
|
|
|
|
* 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:
|
|
|
|
* |
|
|
|
//
|
|
|
|
* Thread-safety: |
|
|
|
// State transitions take immediate effect if the object is used from a single thread. Subclasses
|
|
|
|
* |
|
|
|
// might offer stronger guarantees.
|
|
|
|
* 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.
|
|
|
|
* 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. |
|
|
|
|
|
|
|
*/ |
|
|
|
@interface GRXWriter : NSObject |
|
|
|
@interface GRXWriter : NSObject |
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
* This property can be used to query the current state of the writer, which determines how it might |
|
|
|
// the corresponding value, and that's useful for advanced use cases like pausing an writer. For
|
|
|
|
* currently use its writeable. Some state transitions can be triggered by setting this property to |
|
|
|
// more details, see the documentation of the enum further down.
|
|
|
|
* 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. |
|
|
|
|
|
|
|
*/ |
|
|
|
@property(nonatomic) GRXWriterState state; |
|
|
|
@property(nonatomic) GRXWriterState state; |
|
|
|
|
|
|
|
|
|
|
|
// 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
|
|
|
|
* Transition to the Started state, and start sending messages to the writeable (a reference to it |
|
|
|
// sent later in the future. See GRXWriteable.h for the different messages a writeable can receive.
|
|
|
|
* 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).
|
|
|
|
* 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.
|
|
|
|
* |
|
|
|
|
|
|
|
* This method might only be called on writers in the NotStarted state. |
|
|
|
|
|
|
|
*/ |
|
|
|
- (void)startWithWriteable:(id<GRXWriteable>)writeable; |
|
|
|
- (void)startWithWriteable:(id<GRXWriteable>)writeable; |
|
|
|
|
|
|
|
|
|
|
|
// Send writesFinishedWithError:errorOrNil to the writeable. Then release the reference to it and
|
|
|
|
/**
|
|
|
|
// transition to the Finished state.
|
|
|
|
* 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.
|
|
|
|
* |
|
|
|
|
|
|
|
* This method might only be called on writers in the Started or Paused state. |
|
|
|
|
|
|
|
*/ |
|
|
|
- (void)finishWithError:(NSError *)errorOrNil; |
|
|
|
- (void)finishWithError:(NSError *)errorOrNil; |
|
|
|
@end |
|
|
|
@end |
|
|
|