-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
Description
Hi,
I've just noticed that using new structural coroutines, the code which uses async(start = CoroutineStart.LAZY) { } causes infinite suspend.
As I understand these async(start = CoroutineStart.LAZY) is now treated as a children of TestView object and new coroutine engine waits until these async completes. Shouldn't LAZY async coroutines be excluded from a wait list if they are not running?
Maybe there are more proper way to implement lazy async val?
test example:
class TestView(override val coroutineContext: CoroutineContext) : CoroutineScope {
val title: Deferred<String> = async(start = CoroutineStart.LAZY) { "demo" }
val description: Deferred<String> = async(start = CoroutineStart.LAZY) { "desc" }
}
class TestClass {
suspend fun getView(id: Int): TestView = coroutineScope { TestView(coroutineContext = coroutineContext) }
}
runBlocking {
val view = TestClass().getView(123)
}