Gioele Dev
07/17/2023, 4:58 PMGioele Dev
07/17/2023, 4:58 PMsealed class Status(
){
object None : Status()
object Completed : Status()
object CompletedNo : Status()
object Started : Status()
}
Gioele Dev
07/17/2023, 5:00 PMclass 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>)
}
Gioele Dev
07/17/2023, 5:01 PMGioele Dev
07/17/2023, 5:01 PMstatusRepository.getlowStatus().collect { status ->
Gioele Dev
07/17/2023, 5:03 PMJoffrey
07/17/2023, 5:28 PMgetFlowStatus
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.Joffrey
07/17/2023, 5:28 PMgetSuspendStatus()
?Gioele Dev
07/17/2023, 5:38 PMval statusFlow = MutableStateFlow(Status.None)
override suspend fun getSyncFlowStatus(): Flow<Status> = statusFlow
and
override suspend fun setStatus(statusc: Status) {
this.status = status
statusFlow.value = status
}
Joffrey
07/18/2023, 9:49 AMstatus
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