Skip to main content
generateStream returns a Flow<GenerationEvent>. It is not suspending: you get the flow back immediately and collect it.

Signatures

Handling every event

In a ViewModel

Collecting in viewModelScope means the flow is cancelled when the ViewModel clears, so a generation does not outlive the screen.

Errors

Failures are thrown from the collector, so wrap the collection:

Cancelling

Cancel the coroutine:

Flow operators work normally