chanjungskim
01/03/2023, 12:48 PMsuspend fun requestChat(hisId: Long): ApiResponse<RequestableResponse>{
val result = userService.checkRequestableUser(hisId = hisId)
result.onSuccess {
if(this.data.message == RequestStatusType.AVAILABLE.name){
userService.requestChat(RequestChat(respondentId = hisId, chatStarterId = AppConfigure.myId)))
}
}
}
But I get userService.requestChat red line.. because I need to call it in the coroutine.
How can I return the value here???Chrimaeon
01/03/2023, 12:58 PMcheckRequestableUser
without callback.chanjungskim
01/03/2023, 12:58 PMChrimaeon
01/03/2023, 12:59 PMchanjungskim
01/03/2023, 1:13 PMDmitry
01/03/2023, 1:53 PMFlow
and chain requests together like this:
fun fetchedTrackedLaws() {
val lawCodes = cacheRepository.lawCodes.toTypedArray()
viewModelScope.launch {
flowOf(*lawCodes)
.flatMapMerge { it ->
repository.getLawByNumber(it)
}
.onStart { state.update { state -> state.copy(isLoading = false) } }
.collect { result ->
when(result) {
is Response.Data -> { state.update { state -> state.copy(billsWhichTracked = result.data, isLoading = false) } }
is Response.Error -> { state.update { state -> state.copy(errors = state.errors.plus(getErrorMessage(result)), isLoading = false) } }
}
}
}
}