1

Can someone give me a use case of Produce? I don't quite understand its purpose as I have been exclusively using Publish.

Is the only difference is that with Produce it will send a callback immediately when a class subscribes to the bus? So you can Produce something prior to a class registering and have that class get the result?

Alan
  • 9,331
  • 14
  • 52
  • 97
  • 1
    I tend to think of it as being analogous to sticky events with greenrobot's EventBus. If you supply a producer for an event type, you can implement your own event caching, so when some component registers for that event type, you give it the latest event of that type via the producer. – CommonsWare Mar 11 '16 at 20:11

1 Answers1

3

Similar to what CommonsWare commented:

According to the Otto docs (http://square.github.io/otto/), the @Produce annotation is intended to provide new subscribers with the current state of some event. To see the need for this functionality, consider the following sequence:

  1. ProducerA publishes some really important data
  2. Some time later, SubscriberA subscribes to the same really important data

Without using the @Produce functionality, SubscriberA would not receive the really important data. However, if a producer of the "really important data" is defined then the same sequence becomes:

  1. ProducerA publishes some really important data
  2. Some time later, SubscriberA subscribes to the same really important data
  3. SubscriberA receives data from the producer of the really important data

Therefore producers can provide information to "late joiner" subscribers that would otherwise miss information that was published before the subscriber registered.

curob
  • 705
  • 4
  • 17