Hunter
02/13/2026, 3:54 PMsuspendCoroutine and an inner suspendCoroutine created inside the first, can I do an "early return" to the outer coroutine without ever resuming the inner one without leaking resources? Ex.
suspend fun get(): Int = suspendCoroutine { cont1 ->
val maybe = LazySuspending { getSomethingOrNull() ?: suspendCoroutine { cont1.resume(0) } }
val result = somethingThatRequiresNonNull(maybe)
cont1.resume(result)
}
Here I need this because I need to create a "lazy" getter for something that may be null, but the caller expects it to exist. Is this a viable way to solve the problem?Youssef Shoaib [MOD]
02/13/2026, 3:56 PMsuspendCancellableCoroutine and cancel the inner coroutine when that happens, or just use Arrow's Raise instead (which is specifically made for "early-returning"/non-local control flow, and works extremely well with coroutines by using the same cancellation mechanism)Zach Klippenstein (he/him) [MOD]
02/19/2026, 8:49 PMsuspendCoroutine and use higher-level coroutine primitives for more things, which make it harder to break structured concurrency.