https://kotlinlang.org logo
#coroutines
Title
# coroutines
m

myanmarking

10/15/2019, 2:50 PM
Copy code
mainScope.launch{
	
			onDateChanged // conflatedBroadcastChannel
                .asFlow()
                .distinctUntilChanged()
                .collect{ ... }

            onTimeChanged // conflatedBroadcastChannel
                .asFlow()
                .distinctUntilChanged()
                .collect{ ... }
}
j

Jacques Smuts

10/15/2019, 3:01 PM
launch two separate coroutines.
mainScope.launch { onDateChanged….} mainScope.launch { onTimeChanged…}
m

myanmarking

10/15/2019, 3:04 PM
can i do it this way, i need access to the same scope
Copy code
mainScope.launch{

			val someValue = withContext(<http://dispatchers.IO|dispatchers.IO>){...}
	
			launch{
				onDateChanged // conflatedBroadcastChannel
	                .asFlow()
	                .distinctUntilChanged()
	                .collect{ ... } // someValue used here
			}

            launch{
	            onTimeChanged // conflatedBroadcastChannel
	                .asFlow()
	                .distinctUntilChanged() 
	                .collect{ ... } // someValue used here
            }
}
v

Vsevolod Tolstopyatov [JB]

10/15/2019, 3:26 PM
you can use
onEach
+ `launchIn`:
Copy code
onTimeChanged // conflatedBroadcastChannel
                .asFlow()
                .distinctUntilChanged()
                .onEach { /* collect body */ }
                .launchIn(mainScope)
😲 2
👏 1
m

myanmarking

10/15/2019, 3:27 PM
ok. so i dont have the two inner launches then? Gonna try, thanks
4 Views