Stan Potemkin
01/11/2021, 4:29 AMsharedFlow.collect { println("first") }
sharedFlow.collect { println("second") }
But actually 10 taps results in 10 prints of "first" message and never prints the "second" one.
Does the shared flow accept only one collector, or could it's behavior widely depend on configuration and usage?Ali Albaali
01/11/2021, 10:53 AMsuspend fun flowProgress(block: (Flow<Int>) -> Unit) {
block(
flow {
do {
val progress: Int // .... getting progress
emit(progress)
} while (true)
}
)
}
The other uses plain callback function:
suspend fun intProgress(block: (Int) -> Unit) {
do {
val progress: Int // .... getting progress
block(progress)
} while (true)
}
Can somebody tell me what's the difference between these two and why should I go with one over the other?Pratik Tandel
01/11/2021, 5:47 PMSingle
, Flowable
etczak.taccardi
01/11/2021, 7:11 PMUnit
every X
milliseconds while it has a subscriber. What’s the idiomatic approach for this?rednifre
01/12/2021, 3:45 PMPablo
01/12/2021, 4:17 PMwithContext(<http://Dispatchers.IO|Dispatchers.IO>)
but what if I have some mappers and some business logic? Is it safe to remove the withContext(<http://Dispatchers.IO|Dispatchers.IO>)
?Rechee Jozil
01/12/2021, 6:26 PMvineethraj49
01/12/2021, 7:54 PMStreamingOutput
before?WukongRework.exe
01/12/2021, 11:02 PMMark
01/13/2021, 2:31 AMCancellationException
? For example, any inline (not suspending) higher order function could innocently be catching Exception
and converting to some sealed class. It knows nothing about coroutines and so would have no reason to give special treatment to CancellationException
.
fun main() {
runBlocking {
val job = launch {
test {
delay(1000L)
println("finished long delay")
}
println("finished test")
}
delay(100L)
job.cancel()
}
}
inline fun test(block: () -> Unit) {
try {
block()
} catch (e: Exception) {
println(e.toString())
}
}
// kotlinx.coroutines.JobCancellationException: StandaloneCoroutine was cancelled; job="coroutine#2":StandaloneCoroutine{Cancelling}@de0a01f
// finished test
Pablo
01/13/2021, 8:12 AMCoroutineScope
as a parameter with dagger like
fun provideFragmentScope(fragment: MyFragment): CoroutineScope = fragment.lifecycleScope
if on onDestroyView
I put lifecycleScope.coroutineContext.cancelChildren()
then is a good praxis to cancel coroutines? Note I'm not using ViewModel
so I have to cancel it manually...Simon Lin
01/13/2021, 8:39 AMflowOf(1, 2, 3, 2, 1, 2, 3)
.startCollectWhen { it == 3 }
.collect { print(it) }
// Result: 3, 2, 1, 2, 3
Peter Ertl
01/13/2021, 10:40 PMjeff
01/13/2021, 11:01 PMFunkyMuse
01/14/2021, 8:01 AMRechee Jozil
01/15/2021, 1:30 AMparth
01/15/2021, 2:27 PMeygraber
01/15/2021, 7:52 PMWukongRework.exe
01/16/2021, 6:29 AMShmuel Rosansky [G]
01/17/2021, 5:42 PMfun main() {
println("Outer")
CoroutineScope(Dispatchers.Default).launch {
getFlow()
.onEach { println("Value: $it") }
.collect()
}
}
fun getFlow() = callbackFlow<Int> {
println("Inner")
delay(1)
sendBlocking(0)
}
Shouldn't Outer
get printed first?Michal Klimczak
01/17/2021, 9:09 PMCoroutineScopes
cheap? Can I just create a MainScope()
or sth for e.g. every usecase execution or does it come with some significant overhead?
it's a specific use case in kotlin multiplatform where I would rather create it every time than reuse it for a much more concise code.bjonnh
01/18/2021, 12:21 AMnitrog42
01/18/2021, 3:44 PMByron Katz
01/18/2021, 5:05 PMjames
01/19/2021, 2:28 PMFuture
or CompletableFuture
in JVM > 8 within suspendCoroutine
what's the suggested pattern for interaction. From what I can tell, the suspendCoroutine
is designed for an asynchronous callback but from what I can tell JDK 11, 12, 13 and 14 don't have a way to implement a CompletionStage interface.Nikky
01/19/2021, 5:42 PMtake
it closes the flowjohnaqel
01/20/2021, 2:16 AMsamuel
01/20/2021, 12:51 PMdebounce
on android:
java.lang.AbstractMethodError: abstract method "kotlinx.coroutines.DisposableHandle kotlinx.coroutines.Delay.invokeOnTimeout(long, java.lang.Runnable, kotlin.coroutines.CoroutineContext)"
this is an example of how it arises
myScope.launch {
myFlow
.debounce(500)
.collect {
Timber.e("received input $it")
}
}
Anyone know what causes this?christophsturm
01/20/2021, 2:24 PMSlackbot
01/20/2021, 4:55 PMSlackbot
01/20/2021, 4:55 PMstreetsofboston
01/20/2021, 5:04 PMtaer
01/20/2021, 7:42 PM