1

I am trying to understand how a Flow works by looking at the SharedFlowImpl class. As the Flow interface ensures that all classes which implement Flow must override the collect method, it seemed like the obvious choice of method to peruse first. On the first line of the collect method we have val slot = allocateSlot() where slot is of type SharedFlowSlot.

From looking at the code, I can surmise the following:

  1. There is a 1:1 correspondence between the number of collectors and the number of SharedFlowSlot.
  2. A collector is equivalent to the number of subscribers which is equivalent to the number of times collect is called.
  3. The index property inside the SharedFlowSlot serves as the index of the flow value to be emitted to the collector and it is initialised as the replayIndex.

Am I going along the right lines?

220284
  • 95
  • 7

0 Answers0