Skip to content

Fix #938 — fixes resource handling in Iterant.repeat, adds Iterant.retryIfEmpty#965

Merged
alexandru merged 4 commits into
monix:masterfrom
alexandru:issue-038
Jul 31, 2019
Merged

Fix #938 — fixes resource handling in Iterant.repeat, adds Iterant.retryIfEmpty#965
alexandru merged 4 commits into
monix:masterfrom
alexandru:issue-038

Conversation

@alexandru
Copy link
Copy Markdown
Member

See #938 for the bug description.

This PR fixes iterant.repeat to handle resources (Scope) correctly.

Because repeat returns empty on empty streams, this PR also adds a new retryIfEmpty operator:

import scala.util.Random

val stream = Iterant[Coeval].suspend(Coeval {
  val nr = Random.nextInt()
  if (nr % 10 != 0)
    Iterant[Coeval].empty[Int]
  else
    Iterant[Coeval].of(1, 2, 3)
})

stream.retryIfEmpty(None).repeat

Copy link
Copy Markdown
Collaborator

@oleg-py oleg-py left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure that we want to special-case empty streams in this fashion (e.g. fs2 doesn't do that), but resources not staying open is the most important thing here, so we probably should go ahead.

@alexandru alexandru merged commit f2e53ca into monix:master Jul 31, 2019
mdedetrich pushed a commit to mdedetrich/monix that referenced this pull request Mar 28, 2020
…nt.retryIfEmpty (monix#965)

* Fix monix#938, also add Iterant.retryIfEmpty

* Simplify Iterant.repeat

* Add comments

* Add comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants