question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Promote CoroutineStart.UNDISPATCHED to non experimental API

See original GitHub issue

I use it quite often in places where I know it’s safe to use, with the following import alias:

import kotlinx.coroutines.CoroutineStart.UNDISPATCHED as Undispatched

It’d be great to not have to have to add @UseExperimental(ExperimentalCoroutinesApi::class) to each usage.

I’m interested to know of any considerations that could justify leaving it experimental, postponing that decision or replacing it with something else (like a startDispatched: Boolean = true parameter).

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (5 by maintainers)

github_iconTop GitHub Comments

2reactions
qwwdfsadcommented, Jan 29, 2021

Note:

We’ve discussed internally and decided that the difference between Dispatchers.Unconfined and CoroutineStart.UNDISPATCHED (the latter does not form an event loop) is expected and advanced users (that know when they need UNDISPATCHED) know the difference and won’t be surprised.

2reactions
adampcommented, Jan 26, 2021

We run into cases where we often want to initiate a concurrent process from a non-suspending context and ensure that we’ve run to a first suspension point to await incoming work. In compose this most recently has come up when we need to start a Recomposer before synchronously creating new compositions bound to it; if we can start the recomposition loop undispatched, we know we have not failed to observe any snapshot state invalidations that happened in between initial composition and the recomposition loop and associated snapshot observation beginning. Missing this window due to dispatch can mean we perform some initial composition work twice.

The shape of the use case reduces to something analogous to:

val channel = Channel<Data>()
coroutineScope.launch(start = CoroutineStart.UNDISPATCHED) {
    for (item in channel) {
        performWork(item)
    }
}
channel.offer(dataItem) // should return true and submit dataItem to the already-receiving job
Read more comments on GitHub >

github_iconTop Results From Across the Web

CoroutineStart.UNDISPATCHED - kotlinx-coroutines-core
Immediately executes coroutine until its first suspension point in the current thread as if it the coroutine was started using Unconfined dispatcher.
Read more >
Promote CoroutineStart.UNDISPATCHED to non experimental API ...
I'm interested to know of any considerations that could justify leaving it experimental, postponing that decision or replacing it with something else (like...
Read more >
FlowPreview - Kotlin
According to the feedback, Flow will be refined on its road to stabilization and promotion to a stable API. The best way to...
Read more >
Change log for kotlinx.coroutines - GitHub
`@ExperimentalTime` is no longer needed for methods that use `Duration` (#3041). ... UNDISPATCHED` promoted to stable API (#1393) * Kotlin updated to 1.4.30 ......
Read more >
WhatsNew 2.0 | Ktor Framework
Kotlin Server and Client Framework for microservices, HTTP APIs, and RESTful services. ... WebSocketDeflateExtension not following RFC.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found