In Kotlin I have a LiveData flag set to true inside a function when a new string is available for processing.
There are multiple observers tied to this flag. By default if the flag is set true or false (flag.postValue(true) & flag.postValue(false)) the observers will all be triggered.
I cannot use the flag value ( if(it){...} ) to execute code inside the observers, since clearing the flag in any observer will result in subsequent observers reading the flag incorrectly.
My current workaround is, to instead of setting the flag to true when a string is available, I changed the flag from a Boolean to an Int and just change its value flag.postValue(flag.value*-1). This results in the observers all being triggered correctly.
Is there a more elegant way of doing this or a method to trigger observers even if the variable being observed did not change value?