Hi guys, super quick question.
Is there any way to create a cold observable that emits value only once for first subscription made to that observable? It would require an observable with some kind of a memory, or something like that?
An observable that passes this test (Observable.just is just a placeholder):
Copy code
@Test
fun `assert observable fires only once ever`() {
val testObservable = Observable.just(true)
testObservable.test().assertValue(true)
testObservable.test().assertNoValues()
}
r
reline
09/19/2019, 3:19 PM
If you’re okay with using experimental coroutines, I think this would work
Copy code
val channel = Channel<Boolean>(CONFLATED)
channel.offer(true)
val testObservable = channel.consumeAsFlow().asObservable()
testObservable.test().assertValue(true)
testObservable.test().assertNoValues()