New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Iterant.resource(...).repeat doesn't release any resources until the very end #938
Comments
Yep, current implementation is broken. The naive implementation of repeat via concat ( And that is probably okay. Because from effectful stream being empty on first evaluation, doesn't follow that it would be empty on the next one. I.e., with current test("Iterant.repeat properly repeats evaluation") { _ =>
val I = Iterant[Coeval]
val sample = I.suspend {
var empty = true
I.suspend {
if (empty) I.eval { empty = false; 0 }.drop(1)
else I.pure(42)
}.repeat
}
assertEquals(sample.take(3).toListL.value(), List(42, 42, 42))
} This is directly at odds with this test: test("Iterant.repeat terminates if the source is empty") { implicit s =>
val source1 = Iterant[Coeval].empty[Int]
val source2 = Iterant[Coeval].suspendS(Coeval(source1))
val source3 = Iterant[Coeval].nextCursorS[Int](BatchCursor(), Coeval(source2))
val source4 = Iterant[Coeval].nextBatchS[Int](Batch.empty[Int], Coeval(source3))
assertEquals(source1.repeat.toListL.value(), List.empty[Int])
assertEquals(source2.repeat.toListL.value(), List.empty[Int])
assertEquals(source3.repeat.toListL.value(), List.empty[Int])
assertEquals(source4.repeat.toListL.value(), List.empty[Int])
} because once the tail is in @alexandru do you agree with my logic here? Any objections to removing non-emptiness assumption from |
I'm not sure if this is intentional, but if I construct an Iterant via the
.resource
helper, then.repeat
it, it will repeatedly allocate the resource, then when the stream is done, it will deallocate all of the resources. I expected it to release the allocated resource each time a new "repeat" iteration started.A minimal example:
If I run
nums.repeat.take(9).foreach(println)
I get:But if I run
(nums ++ nums ++ nums).foreach(println)
I get what I was expecting from the "repeat" version:I'm using Monix 3.0.0-RC2
The text was updated successfully, but these errors were encountered: