It’s possible to make Coroutine Actor
prevent that I send duplicated value?
Eg:
I use this sealed class
to send values to actor
sealed class LoginCommand {
class LOGIN(val email: String, val password: String) : LoginCommand()
class LOGIN_VALIDATE(val email: String, val password: String) : LoginCommand()
class SAVE_USER_DATA(val email: String, val password: String) : LoginCommand()
object USER_IV : LoginCommand()
}
And the actor call:
private val eventActor = viewModelScope.actor<LoginCommand>(Dispatchers.Main, Channel.RENDEZVOUS) {
for (command in channel) {
when (command) {
is LoginCommand.LOGIN -> {
loadingStateLiveData.postValue(true)
loginLiveData.postValue(loginRepository.getLogin(Login(command.email, command.password)))
loadingStateLiveData.postValue(false)
}
is LoginCommand.SAVE_USER_DATA -> {
loginSavedRepository.saveUserData(command.email, command.password)
}
}
}
}
I need to prevent that can send LoginCommand.LOGIN
and LoginCommand.SAVE_USER_DATA
two times, but permit to send LoginCommand.LOGIN
and LoginCommand.SAVE_USER_DATA
at the same same time… Only block the duplicated. It’s possible?
(I know that Channel.RENDEZVOUS
keep just one call at time, it’s just a sample, because I implemented that and now I will need to implemented a new actor that accept many calls but block duplicated calls…)