You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Should print 0,1,10,11 but actually prints 0,1,10,11,20,21,30,31. Changing the outer take(4) to take(1) produces 0,10,11,20,21,30,31.
I believe the AbortFlowException of the outer take(4) is being swallowed by the inner take(2). I rewrote the take operator locally and had it track its specific AbortFlowException and rethrow if it did not match and that corrected the problem.
fun <T> Flow<T>.take(count:Int): Flow<T> {
require(count >0) { "Requested element count $count should be positive" }
return flow {
// Creating the exception eagerly is obviously expensive but it was easy for testingval ours =AbortFlowException()
var consumed =0try {
collect { value ->
emit(value)
if (++consumed == count) {
throw ours
}
}
} catch (e:AbortFlowException) {
if (e != ours) throw e
}
}
}
There might be errors when combining other operators that use AbortFlowException as it seems to be a common pattern to just ignore this exception when thrown.
The text was updated successfully, but these errors were encountered:
Example code for 1.3.2:
Should print
0,1,10,11
but actually prints0,1,10,11,20,21,30,31
. Changing the outertake(4)
totake(1)
produces0,10,11,20,21,30,31
.I believe the
AbortFlowException
of the outertake(4)
is being swallowed by the innertake(2)
. I rewrote thetake
operator locally and had it track its specificAbortFlowException
and rethrow if it did not match and that corrected the problem.There might be errors when combining other operators that use
AbortFlowException
as it seems to be a common pattern to just ignore this exception when thrown.The text was updated successfully, but these errors were encountered: