Javier
01/12/2021, 9:59 PMEither
, but it seems like the first emission is being mixed if there are more than one emission, so store and store2 are different instances with should have the same emissions:
store.stream().take(1).toList().also { println(it) }
store2.stream().take(2).toList().also { println(it) }
That snippet prints:
[Right(right=Success(data=[1, 2, 3, 4], isLoading=true))]
[Right(right=Success(data=[1, 2, 3, 4, 7, 8], isLoading=true)), Right(right=Success(data=[1, 2, 3, 4, 7, 8], isLoading=false))]
Javier
01/12/2021, 10:00 PMflow {
emit(sourceOfTruth.flow().first().asSuccessLoading<F, S>())
when (val fetch = fetch()) {
is ResourceFailure<F, S> -> emit(fetch)
is ResourceSuccess<S> -> sourceOfTruth.insert(fetch.right.data)
}
emitAll(sourceOfTruth.flow().map { it.asSuccess() })
}
Javier
01/12/2021, 10:03 PMEither
which has the property isLoading = true
with 1, 2, 3, 4, 7, 8
, because 7
and 8
are inserted after the first emission, when it is fetched, and after the first emission, should not be more isLoading = true
Javier
01/12/2021, 10:25 PMMarc Knaup
01/13/2021, 9:31 AMJavier
01/13/2021, 11:10 AMJavier
01/13/2021, 11:11 AMJavier
01/13/2021, 11:11 AMMarc Knaup
01/13/2021, 11:12 AMJavier
01/13/2021, 11:30 AMMarc Knaup
01/13/2021, 11:32 AMsourceOfTruth
. It emits mutable state.
The problem is not that you emit the wrong thing (list). It’s just that that list is changed after it was emitted.Marc Knaup
01/13/2021, 11:33 AMEither
point to the same list that obviously must contain the same elements.Marc Knaup
01/13/2021, 11:34 AMsourceOfTruth
look like?Javier
01/13/2021, 12:24 PMJavier
01/13/2021, 12:24 PMMarc Knaup
01/13/2021, 12:25 PMsourceOfTruth
emits instantly then
• the take(1)
example should be instant
• the take(2)
example should need 3000msJavier
01/13/2021, 12:26 PMJavier
01/13/2021, 12:26 PMMarc Knaup
01/13/2021, 12:27 PMstore.stream().take(1).toList().also { println(it) }
takes 3000ms?Javier
01/13/2021, 12:27 PMJavier
01/13/2021, 12:27 PMJavier
01/13/2021, 12:27 PMJavier
01/13/2021, 12:27 PMJavier
01/13/2021, 12:28 PMemit(sourceOfTruth.flow().first().asSuccessLoading<F, S>())
Marc Knaup
01/13/2021, 12:28 PMJavier
01/13/2021, 12:29 PMsourceOfTruth.flow().first()
to something like sourceOfTruth.get()
without sharing the same flow and it works but I still would like to know what was happeningJavier
01/13/2021, 12:29 PMJavier
01/13/2021, 12:29 PMJavier
01/13/2021, 12:29 PMJavier
01/13/2021, 12:29 PMJavier
01/13/2021, 12:30 PMMarc Knaup
01/13/2021, 12:30 PMsourceOfTruth
.
I also don’t know the difference between store
and store2
, or if you reuse any stores in your tests.Javier
01/13/2021, 12:31 PMJavier
01/13/2021, 12:32 PMMarc Knaup
01/13/2021, 12:32 PMMarc Knaup
01/13/2021, 12:33 PMtake(1).toList()
is instant then should be .first()
and .collect { println(it) }
.Marc Knaup
01/13/2021, 12:33 PMMarc Knaup
01/13/2021, 12:34 PMfetch
use delay
or Thread.sleep
? 🤔Javier
01/13/2021, 12:36 PMdelay
Javier
01/13/2021, 12:36 PMdelay
I was having the same problemMarc Knaup
01/13/2021, 12:36 PMtake(n)
uses .collect
too so both should work.Javier
01/13/2021, 12:37 PMJavier
01/13/2021, 12:37 PMMarc Knaup
01/13/2021, 12:38 PMprint
into the emitting code and see where it stopsJavier
01/13/2021, 12:38 PMJavier
01/13/2021, 12:38 PMJavier
01/13/2021, 12:39 PMflow {
val source = sourceOfTruth.flow().first().asSuccessLoading<F, S>()
println(source)
emit(source)
when (val fetch = fetch()) {
is ResourceFailure<F, S> -> emit(fetch)
is ResourceSuccess<S> -> sourceOfTruth.insert(fetch.right.data)
}
emitAll(sourceOfTruth.flow().map { it.asSuccess() })
}
Javier
01/13/2021, 12:39 PMMarc Knaup
01/13/2021, 12:40 PMJavier
01/13/2021, 12:40 PMJavier
01/13/2021, 12:41 PM[Right(right=Success(data=[1, 2, 3, 4], isLoading=true))]
[Right(right=Success(data=[1, 2, 3, 4, 7, 8], isLoading=true)), Right(right=Success(data=[1, 2, 3, 4, 7, 8], isLoading=false))]
Javier
01/13/2021, 12:42 PMMarc Knaup
01/13/2021, 12:42 PMsourceOfTruth.insert
.Javier
01/13/2021, 12:42 PMJavier
01/13/2021, 12:42 PMJavier
01/13/2021, 12:43 PMRight(right=Success(data=[1, 2, 3, 4], isLoading=true)) // internal println()
Right(right=Success(data=[1, 2, 3, 4, 7, 8], isLoading=true)) // first collect println(), and it takes 3000 ms
Right(right=Success(data=[1, 2, 3, 4, 7, 8], isLoading=false)) // second collect println()
Marc Knaup
01/13/2021, 12:43 PMfetch
having a delay?Javier
01/13/2021, 12:43 PMJavier
01/13/2021, 12:44 PMMarc Knaup
01/13/2021, 12:44 PMMarc Knaup
01/13/2021, 12:44 PMJavier
01/13/2021, 12:51 PM