FunkyMuse
01/25/2021, 10:43 AMprotected val loadingState = BroadcastChannel<Boolean>(Channel.BUFFERED)
val actionReceiver = loadingState.asFlow()
Shalom Halbert
01/25/2021, 2:37 PMSharedFlow
is what you want to useShalom Halbert
01/25/2021, 2:37 PMAdam Powell
01/25/2021, 3:42 PMval loadingChannel = Channel<Boolean>(Channel.BUFFERED)
val loadingFlow = loadingChannel.receiveAsFlow()
Adam Powell
01/25/2021, 3:42 PMloadingChannel
and observe using loadingFlow
.FunkyMuse
01/25/2021, 3:42 PMFunkyMuse
01/25/2021, 3:43 PMAdam Powell
01/25/2021, 3:43 PMChannel.receiveAsFlow
then no value will be emitted more than once. Are you sure your other code isn't sending to the channel more than once?FunkyMuse
01/25/2021, 3:44 PMAdam Powell
01/25/2021, 3:45 PMAdam Powell
01/25/2021, 3:46 PMFunkyMuse
01/25/2021, 3:47 PMAdam Powell
01/25/2021, 3:57 PMFunkyMuse
01/25/2021, 9:39 PMAdam Powell
01/26/2021, 12:05 AMlaunchWhenResumed
block runs as expected, before the collect
call begins?FunkyMuse
01/26/2021, 10:48 AMFunkyMuse
01/26/2021, 12:54 PMFunkyMuse
01/26/2021, 12:56 PMFunkyMuse
01/26/2021, 12:56 PMFunkyMuse
01/26/2021, 12:56 PMFunkyMuse
01/26/2021, 12:57 PMFunkyMuse
01/26/2021, 12:58 PMval Fragment.viewCoroutineScope get() = viewLifecycleOwner.lifecycle.coroutineScope
FunkyMuse
01/26/2021, 12:58 PMOleksandr Balan
01/26/2021, 1:02 PMcollectSubtitles
is blocking.
I bet you start to collect a Flow
there 🙂FunkyMuse
01/26/2021, 1:02 PMFunkyMuse
01/26/2021, 1:10 PMFunkyMuse
01/26/2021, 1:15 PM.onEach{}.launchIn(scope)
and put it inside the onResumed block, would it be called in onResume since it's launched in the scope with launchIn?Adam Powell
01/26/2021, 3:05 PMlaunch
inside a single launchWhenResumed
Adam Powell
01/26/2021, 3:06 PM...launchWhenResumed {
launch { collectSubtitles() }
launch { handleDownloadStatus() }
}
FunkyMuse
01/26/2021, 3:07 PMOleksandr Balan
01/26/2021, 3:16 PMscope.launchWhenResumed {
launch { collectSubtitles() }
launch { handleDownloadStatus() }
}
and
scope.launchWhenResumed { collectSubtitles() }
scope.launchWhenResumed { handleDownloadStatus() }
?Adam Powell
01/26/2021, 9:18 PM