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:
- There is a 1:1 correspondence between the number of collectors and the number of
SharedFlowSlot. - A collector is equivalent to the number of subscribers which is equivalent to the number of times
collectis called. - The index property inside the
SharedFlowSlotserves as the index of the flow value to be emitted to the collector and it is initialised as thereplayIndex.
Am I going along the right lines?