Skip to content

Coroutines guide should highlight the dangers of runBlocking #4412

Open
@dkhalanskyjb

Description

@dkhalanskyjb

Reported by @joffrey-bion in the Kotlinlang Slack.

Currently, the coroutines guide uses runBlocking freely to explain the concept of coroutines. However, in practice, runBlocking does not have such a prominent role and is often error-prone: #4242

At the top level, there is an alternative to runBlocking:

suspend fun main() {
    coroutineScope {
        // code goes here
    }
}

It's not without its issues, though: it silently introduces multithreading (because no dispatcher is specified, Dispatchers.Default is used).

I don't see a way around using the single-threaded runBlocking for some of the examples, but the issues with runBlocking should be highlighted.

Metadata

Metadata

Assignees

No one assigned

    Labels

    guideIssues with the coroutines guide on the website

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions