Hi I have a repositorty singleton where i use a St...
# coroutines
g
Hi I have a repositorty singleton where i use a Status prop and i'd like to trigger every change
Copy code
sealed class Status(
){
    object None : Status()
    object Completed : Status()
    object CompletedNo : Status()
    object Started : Status()
}
Copy code
class StatusRepositoryImpl @Inject constructor() : SyncStatusRepository {

    private var status: Status = Status.None
    override suspend fun setStatus(status: Status) {
        this.status = status
    }
    override fun getStatus(): Status = status

    override suspend fun geSuspendStatus(): Status {
        return status
    }

    override suspend fun getFlowStatus(): Flow<Status> = flow {
        emit(status)
    }.flowOn(<http://Dispatchers.IO|Dispatchers.IO>)
}
i change satus prop and i' d like a triggering
Copy code
statusRepository.getlowStatus().collect { status  ->
when i change status with statusRepository.setStatus(Status.Complete) trigger doesn/t wok
j
I'm not sure what you expected to happen here.
getFlowStatus
returns a flow a single value which is equal to the current value of
status
at the moment of the call. If you want to get updates, you should consider using a
StateFlow<Status>
to hold the status value instead of a regular property.
Also, what's the point of
getSuspendStatus()
?
g
ok i'm trying .
Copy code
val  statusFlow = MutableStateFlow(Status.None)
override suspend fun getSyncFlowStatus(): Flow<Status> = statusFlow
and
Copy code
override suspend fun setStatus(statusc: Status) {
    this.status = status
    statusFlow.value = status
}
j
You don't really need the
status
property at all if you already have a
StateFlow
containing the state. You can access the state of the flow in a non-suspending way by accessing
statusFlow.value