Skip to content

Flow hangs even when using terminal operators #4035

Closed
@ansman

Description

@ansman

Describe the bug

A flow that uses take(1), onCompletion { if (it == null) awaitCancellation() } and first() can hang forever instead of returning the first value.

Interestingly, removing take(1) will cause the flow to behave as expected.

Provide a Reproducer
Here is such an example:

flowOf(1)
    .take(1)
    .onCompletion { if (it == null) awaitCancellation() }
    .first()

This code is expected to return 1, instead if suspends forever. If you remove take(1) it returns 1 as expected.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions