Running a suspending function after a transformation.map

Viewed 332

I used to have this code in my repository:

override val allowUse:LiveData<Boolean> = Transformations.map(preferences.accountLiveData) {
                                              if (it.isNullOrBlank()) {
                                                 false
                                              } else {
                                                 validateAccount(it)
                                              }
                                          }

the validateAccount function was a normal function that would return results immediately

now I have to make 'validateAccount` a suspending function in order to perform some network actions

one idea I had was to observe accountLiveData and when a change occured I would call the (now suspending) validateAccount using the repository's scope and when I got the result I would post the value to the allowUse LiveData which would become a seperate MutableLiveData<Boolean>

Is there a way to do this so I can call a the now suspending validateAccount from a transformation?

0 Answers
Related