Skip to content

Flow.collectLatest is error-prone because of no CoroutineScope #3533

Open
@dovchinnikov

Description

@dovchinnikov
launch {
  aFlow.collectLatest {
    async { 
      // uses CoroutineScope from launch => not cancelled when collectLatest block is cancelled
    }
  }
}

It should not be possible to use launch/async/etc inside collectLatest {} (e.g. by means of @DslMarker) OR the block should get CoroutineScope receiver.

Easy to forget workaround:

launch {
  aFlow.collectLatest {
    coroutineScope {
      async {
        // ...
      }  
    }
  }
}

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