rnett
07/18/2025, 11:35 PMforClasses(ReentrantLock::class).allMethods().ignore()
correctly ignore fun <T> ReentrantLock.withLock(block: () -> T)
?Eugen Martynov
07/21/2025, 11:54 AMval waithForDBSave = async { setupListenerAndWait() }
db.save() // I want to wait before executing here to be sure listener was setup
waitForDBSave.await()
Atul Gupta
07/22/2025, 8:37 PMrunTest
in commonTest and add the debug point for more than 1m, it crashes with below exception
After waiting for 1m, the test body did not run to completion
kotlinx.coroutines.test.UncompletedCoroutinesError: After waiting for 1m, the test body did not run to completion
shouldn't it see that debug is attached and and don't count that time(when it is attached)?Lukasz Kalnik
07/25/2025, 8:57 AMTestScope
, how can I manually control the passing of virtual time inside a suspending function?
suspend fun doSomethingDelayed() {
delay(10.seconds)
println("Delayed action completed")
}
Rob
07/27/2025, 4:35 PM谢朋刚
08/01/2025, 3:01 AMresumeWithException
and directly throwing an Exception
within a suspend function?CLOVIS
08/04/2025, 2:07 PMAugust Lilleaas
08/04/2025, 4:48 PMsuspend fun <T> CoroutineScope.logSlowQueries(
timeoutSeconds: Long?,
block: suspend () -> T
): T {
val slowQueryDetectorJob = async {
delay(Duration.ofSeconds(timeoutSeconds ?: 10))
val otelCtx = Span.current().spanContext
if (otelCtx.isValid) {
log.error("Query not completed after $timeoutSeconds seconds - traceId=${otelCtx.traceId} spanId=${otelCtx.spanId}")
} else {
log.error("Query not completed after $timeoutSeconds seconds - NO OTEL CTX AVAILABLE")
}
}
return try {
block()
} finally {
slowQueryDetectorJob.cancel()
}
}
Zach Klippenstein (he/him) [MOD]
08/04/2025, 5:33 PMcoroutineScope
in your function body so the caller doesn’t need to pass one in, and it t would be more idiomatic to use launch
instead of async
since the timing coroutine doesn’t need to return a value.kevin.cianfarini
08/04/2025, 5:38 PMsuspend fun logSlow(logAfter: Duration = 10.seconds, block: suspend () -> T): T = coroutineScope {
val logJob = launch {
delay(logAfter)
log.error(...)
}
return try {
block()
} finally {
logJob.cancel()
}
}
Zach Klippenstein (he/him) [MOD]
08/05/2025, 1:27 AMhawklike
08/06/2025, 7:15 AMmap
, filter
or combine
make hot flow cold, because their internal implementation is basically this:
return flow {
collect { value ->
emit(transform(value))
}
}
So, are the following examples correct?
val stateFlowA = MutableStateFlow("A")
val flowA: Flow<String> = stateFlowA // Is Hot flow
val stateFlowB = MutableStateFlow("B")
val flowB: Flow<String> = stateFlowB.map { it } // Is Cold flow
val flowC: Flow<String> = combine(stateFlowA, stateFlowB) { a, b -> "$a $b" } // Is Cold flow
Thank you 🙏Panos
08/06/2025, 8:59 AM<dependency>
<groupId>org.jetbrains.kotlinx</groupId>
<artifactId>kotlinx-coroutines-core</artifactId>
<version>1.10.2</version>
</dependency>
and in Idea I can not see limitedParallelism
available for any dispatcher. I want to use <http://Dispatchers.IO|Dispatchers.IO>.limitedParallelism(nThreads)
.
Am I missing something fundamental?Edoardo Luppi
08/07/2025, 12:51 PMZoltan Demant
08/07/2025, 1:53 PMflow.flowOn(Default)
where it makes sense; and life is good. Or so I would think, because further down the chain when I do flow.map { .. }
and perform some heavy transformations on the data.. Ill eventually realize that Im doing those on the main-thread, since the backing scope is based on Dispatchers.Main
. I need the results of the flow collection to be delivered on the main thread, but Id basically like all operations on it to be performed on a background one. I know that I can use withContext, specify another .flowOn, or even run the entire flow operation in a background scope - and then switch to main for the delivery.. but these seem reluctant or weird, and Id be repeating myself a lot. Is there any best practices or advice for situations like this?Colton Idle
08/11/2025, 4:13 PMgpopides
08/12/2025, 9:09 PMcompletion exception
link, you get a 404 because the link is https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/-completable-deferred/get-completion-exception-or-null.html which does not exist.
if you remove the -completable
from the link, it links to the correct page
I had a look at the code and indeed getCompletionExceptionOrNull
is part of Deferred
.
Clicking the KDoc link through the IDE works and you get navigated to the function.
Is this a coroutines issue (the link inside KDoc) or Dokka which should generate the correct link?Daniel Pitts
08/13/2025, 10:03 PMsubscriptionCount
a suitable way to track that?bj0
08/15/2025, 6:35 AMMainScope()
into a class that creates a ktor HttpClient
to use for the lifetime of the scope, is there an idiomatic way to cleanup the client when the scope is cancelled? I can only think of launching a do-nothing coroutine that uses awaitCancellation
or using job.invokeOnCompletion
. I'm not sure if one of these are a good method or if there's something else?Rob Elliot
08/15/2025, 9:16 AMThread.interrupt()
by checking Thread.currentThread().isInterrupted
.
Migrating that to currentCoroutineContext().isActive
seemed fairly easy, but higher up the tree, and outside coroutine context, I now need to launch a coroutine and cancel it when the launching thread is interrupted, to maintain the contract.
I've tried this:
fun run() = runBlocking {
val deferred = async(start = LAZY) {
login.login()
}
try {
deferred.await()
} catch (_: InterruptedException) {
deferred.cancel()
deferred.await()
}
}
but my tests are failing in a way that shows that the contract has changed - indeed, it looks like the InterruptedException is not caught by that catch block at all because the lambda passed to runBlocking
is being run in a different thread to fun run()
. But I can't get a reference to deferred
outside runBlocking
! How are coroutines and threads meant to interop for cancellation?bj0
08/15/2025, 10:51 PMflatMapLatest
(https://kotlinlang.org/api/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines.flow/flat-map-latest.html), what happens produced (inner) flow finishes but the receiver flow does not? does it finish or wait for the next inner flow to be produced?theapache64
08/17/2025, 7:19 PMAlex Schiff
08/19/2025, 12:44 PMjoseph_ivie
08/19/2025, 9:58 PMCancellationException
to not be an Exception
? It really doesn't fall under that category. It doesn't represent some kind of issue; it represents that we don't care about the result anymore. It seems like it should inherit from Throwable
and be treated entirely differently.baxter
08/20/2025, 6:40 PMoverride fun getSomeFlow(): Flow<String> =
localDataFlow
.onStart {
// Fire-and-forget, but still tied to the collector's lifecycle.
CoroutineScope(currentCoroutineContext()).launch {
triggerSomePrefetchCaching()
}
}
.map { data ->
data.toSomeString()
}
svenjacobs
08/21/2025, 6:11 AMursus
08/21/2025, 9:40 PM@SingleIn(UserScope::class)
class MyDependency(
@QualifierFor(AppScope::class) private val scope: CoroutineScope
) {
fun foo() {
scope.launch {
// access other fields
}
}
}
since this compiles but is a memory leakursus
08/22/2025, 1:08 PMcombine
conflate or not? Will every component emit get a matching emission out of the combine
?
(I though it will always emit all of the combinations, but I'm seeing some nondeterministic behavior at tests - and now I'm not sure if it's test issue or combine
issue)Andrey Tabakov
08/26/2025, 11:39 AM2025-08-25 22:44:15.278 [DefaultDispatcher-worker-10] WARN a.r.backend.api.KtorApp - null
java.lang.IllegalMonitorStateException: null
at java.base/java.util.concurrent.locks.ReentrantReadWriteLock$Sync.tryRelease(Unknown Source)
at java.base/java.util.concurrent.locks.AbstractQueuedSynchronizer.release(Unknown Source)
at java.base/java.util.concurrent.locks.ReentrantReadWriteLock$WriteLock.unlock(Unknown Source)
at ai.retable.backend.dataflow.processing.design.App.veryImportant(App.kt:619)
Code that cause error:
val lock = ReentrantReadWriteLock() // java.util.concurrent.locks
suspend fun veryImportant() {
lock.write {
withTimeout(TIMEOUT) {
// do some suspend work
}
}
}
Java code that cause an error:
@ReservedStackAccess
protected final boolean tryRelease(int releases) {
if (!isHeldExclusively())
throw new IllegalMonitorStateException();
int nextc = getState() - releases;
boolean free = exclusiveCount(nextc) == 0;
if (free)
setExclusiveOwnerThread(null);
setState(nextc);
return free;
}
protected final boolean isHeldExclusively() {
// While we must in general read state before owner,
// we don't need to do so to check if current thread is owner
return getExclusiveOwnerThread() == Thread.currentThread();
}
So, does it mean I can't use java.util.concurrent.locks.ReentrantReadWriteLock
with Kotlin coroutines because the thread can change?kevin.cianfarini
08/28/2025, 5:40 PMClock
and Instant
are about to go stable in the stdlib, is there any willingness to add a Clock implementation in the test coroutines artifact that reflects the current time of the test scheduler?