This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* A [MutableLiveData] which enables computing the new state from the current one | |
* and updating it atomically | |
*/ | |
class AtomicMutableLiveData<T>(initialValue: T) : MutableLiveData<T>() { | |
private val state = AtomicReference<T>(initialValue) | |
init { | |
super.postValue(initialValue) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @return a channel, that will emit an item when either the [first] or [second] source channel emits a value. | |
* The emitted value will be a [Pair] containing most recently emitted values from both source channels. | |
* | |
* Either of the [Pair]'s values could be null, meaning, that the source channel, which is responsible for this value, hasn't emitted anything yet. | |
*/ | |
fun <T> CoroutineScope.combineLatest( | |
first: ReceiveChannel<T>, | |
second: ReceiveChannel<T> | |
): ReceiveChannel<Pair<T?, T?>> = Channel<Pair<T?, T?>>().also { channel -> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @return a [ReceiveChannel] with a capacity of 1, which will emit every time the given [liveData] emits a value | |
*/ | |
fun <T> CoroutineScope.channelOf(liveData: LiveData<T>) = produce(capacity = 1) { | |
val observer: Observer<T> = Observer { | |
if (it != null) { | |
offer(it) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package example.rx | |
class BackendApi { | |
fun fetchUsers() = listOf( | |
User(420), | |
User(421), | |
User(422) | |
) | |
fun deleteUser(user: User) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dependencies { | |
androidTestUtil 'com.android.support.test:orchestrator:1.0.2' | |
} | |
task installTestUtils() { | |
doFirst { | |
// Resolve and install all files associated with androidTestUtil configuration, which will be both - test services and the orchestrator APKs | |
configurations.androidTestUtil.resolvedConfiguration.files.forEach { filePath -> | |
println "Installing ${filePath} ..." | |
exec { |