RACChannel.h 2.7 KB

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