Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Job join method documentation #2615

Closed
serddmit opened this issue Mar 28, 2021 · 3 comments
Closed

Job join method documentation #2615

serddmit opened this issue Mar 28, 2021 · 3 comments
Labels
docs KDoc and API reference

Comments

@serddmit
Copy link

serddmit commented Mar 28, 2021

I have found very strange documentation for join method:

In particular, it means that a parent coroutine invoking join on a child coroutine that was started using launch(coroutineContext) { ... } builder throws CancellationException if the child had crashed, unless a non-standard CoroutineExceptionHandler is installed in the context.

I'm not sure that CoroutineExceptionHandler will have effect for CancellationException.
Example:

fun main() = runBlocking {
    val handler = CoroutineExceptionHandler { _, exception ->
        println("CoroutineExceptionHandler got $exception")
    }
    val job = GlobalScope.launch(handler) {
        val inner = launch { // all this stack of coroutines will get cancelled
            throw IOException() // the original exception
        }
        try {
            inner.join()
        } catch (e: CancellationException) {
            println("handle join")
        }
    }
    job.join()
}

Output:
handle join CoroutineExceptionHandler got java.io.IOException

So basically CancellationException will still be thrown regardless any installed handlers.

@elizarov elizarov added the docs KDoc and API reference label Mar 30, 2021
elizarov added a commit that referenced this issue Mar 30, 2021
@elizarov
Copy link
Contributor

Good catch. Thanks.

@serddmit
Copy link
Author

Thanks, now it's clear!

@serddmit serddmit reopened this Mar 30, 2021
@serddmit
Copy link
Author

@elizarov, Don't forget to change documentation for cancelAndJoin, it has the same statement.
https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/kotlinx.coroutines/cancel-and-join.html

Thanks

qwwdfsad pushed a commit that referenced this issue Apr 6, 2021
* Fix wrong docs on Job.join and Job.cancelAndJoin

Fixes #2615
pablobaxter pushed a commit to pablobaxter/kotlinx.coroutines that referenced this issue Sep 14, 2022
* Fix wrong docs on Job.join and Job.cancelAndJoin

Fixes Kotlin#2615
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
docs KDoc and API reference
Projects
None yet
Development

No branches or pull requests

2 participants