0

Although SharedFlow is non-sticky, each result will only be processed once, but during the upload process, if you return to the desktop, in the absence of a receiving end, SharedFlow will discard existing messages, instead of suspending events and waiting for another receiver to process them in turn. For example: Loading is sent before uploading, so that the interface has a loading box, but the application uploading process is processed in the background, and the success or failure event are also sent in the background after processing. The message of canceling the loading box will not be received, and the Loading pop-up window of the page will always exist. My Solution: Use [kotlinx.coroutines.flow.StateFlow], or set the replay of [kotlinx.coroutines.flow.MutableSharedFlow] to 1 At this point, it is sticky. The Empty event is added to the event, and Empty is not processed. After processing other events, the UI side sends the Empty event. Or use flow's [kotlinx.coroutines.flow.MutableSharedFlow.resetReplayCache] to empty the replay Expand [Lifecycle.State] to Created, although it can be received, the UI will not process it.

General Grievance
  • 4,555
  • 31
  • 31
  • 45
花未开
  • 159
  • 1
  • 6

0 Answers0