Skip to content

Disallow Job passed as context to withContext/launch/async #3670

Open
@dovchinnikov

Description

@dovchinnikov

What do we have now?

It's possible to pass Job as part of context to the mentioned functions:

withContext(Job()) {
    ...
}
cs.launch(Job()) {
    ...
}
cs.async(Job()) {
    ...
}

What should be instead?

Error should be logged when a Job is detected in the added context.

Why?

All above cases "replace" the context Job and attach the scope Job to the passed Job() as a child.
This might be unexpected at best, and plain dangerous because it breaks parent-child relation.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions