RACChannel.h 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. //
  2. // RACChannel.h
  3. // ReactiveObjC
  4. //
  5. // Created by Uri Baghin on 01/01/2013.
  6. // Copyright (c) 2013 GitHub, Inc. All rights reserved.
  7. //
  8. #import "RACSignal.h"
  9. #import "RACSubscriber.h"
  10. @class RACChannelTerminal<ValueType>;
  11. NS_ASSUME_NONNULL_BEGIN
  12. /// A two-way channel.
  13. ///
  14. /// Conceptually, RACChannel can be thought of as a bidirectional connection,
  15. /// composed of two controllable signals that work in parallel.
  16. ///
  17. /// For example, when connecting between a view and a model:
  18. ///
  19. /// Model View
  20. /// `leadingTerminal` ------> `followingTerminal`
  21. /// `leadingTerminal` <------ `followingTerminal`
  22. ///
  23. /// The initial value of the model and all future changes to it are _sent on_ the
  24. /// `leadingTerminal`, and _received by_ subscribers of the `followingTerminal`.
  25. ///
  26. /// Likewise, whenever the user changes the value of the view, that value is sent
  27. /// on the `followingTerminal`, and received in the model from the
  28. /// `leadingTerminal`. However, the initial value of the view is not received
  29. /// from the `leadingTerminal` (only future changes).
  30. @interface RACChannel<ValueType> : NSObject
  31. /// The terminal which "leads" the channel, by sending its latest value
  32. /// immediately to new subscribers of the `followingTerminal`.
  33. ///
  34. /// New subscribers to this terminal will not receive a starting value, but will
  35. /// receive all future values that are sent to the `followingTerminal`.
  36. @property (nonatomic, strong, readonly) RACChannelTerminal<ValueType> *leadingTerminal;
  37. /// The terminal which "follows" the lead of the other terminal, only sending
  38. /// _future_ values to the subscribers of the `leadingTerminal`.
  39. ///
  40. /// The latest value sent to the `leadingTerminal` (if any) will be sent
  41. /// immediately to new subscribers of this terminal, and then all future values
  42. /// as well.
  43. @property (nonatomic, strong, readonly) RACChannelTerminal<ValueType> *followingTerminal;
  44. @end
  45. /// Represents one end of a RACChannel.
  46. ///
  47. /// An terminal is similar to a socket or pipe -- it represents one end of
  48. /// a connection (the RACChannel, in this case). Values sent to this terminal
  49. /// will _not_ be received by its subscribers. Instead, the values will be sent
  50. /// to the subscribers of the RACChannel's _other_ terminal.
  51. ///
  52. /// For example, when using the `followingTerminal`, _sent_ values can only be
  53. /// _received_ from the `leadingTerminal`, and vice versa.
  54. ///
  55. /// To make it easy to terminate a RACChannel, `error` and `completed` events
  56. /// sent to either terminal will be received by the subscribers of _both_
  57. /// terminals.
  58. ///
  59. /// Do not instantiate this class directly. Create a RACChannel instead.
  60. @interface RACChannelTerminal<ValueType> : RACSignal<ValueType> <RACSubscriber>
  61. - (instancetype)init __attribute__((unavailable("Instantiate a RACChannel instead")));
  62. // Redeclaration of the RACSubscriber method. Made in order to specify a generic type.
  63. - (void)sendNext:(nullable ValueType)value;
  64. @end
  65. NS_ASSUME_NONNULL_END