Coroutines and job progress

I’m building a Kotlin compose desktop app that perform jobs that take minutes, therefore I need to display the job progress. Therefore I need that my that this jobs report the current progress. Note I’m newbie on coroutines.

My solution (simplified) has been that my jobs receive a channel as an argument:

suspend fun generateVideos(progress: Channel<JobProgress>)  {
        return withContext(Dispatchers.IO) {
              // do job and update channel
       }
}

And in the UI part I transform this channel to a flow, then to state

channel.receiveAsFlow().collectAsState(default)

Is this the “correct” way of doing this?

Note:
I have discarded using directly a flow: the job needs to be executed independently that someone is listening to its results.
I don’t like Reactive-like approaches where the ones proposed here: Best practice for coroutine that reports progress where the result of the job is a flow that indicates if the job is finished. In my opinion this complicates the job execution and control.

There are hot flows as well: SharedFlow and StateFlow. In your case StateFlow makes the most sense, because we are probably not interested in receiving past progress events, only the last one. Just create MutableStateFlow, update the progress by setting its value and others can observe changes as a flow.