Skip to content
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

Add Signal.waitUntil #2815

Merged
merged 10 commits into from
Feb 6, 2022
Merged

Add Signal.waitUntil #2815

merged 10 commits into from
Feb 6, 2022

Conversation

SystemFw
Copy link
Collaborator

@SystemFw SystemFw commented Feb 5, 2022

No description provided.

* to change, or waiting for the value of the `Signal` of an
* ordered `Stream[IO, Int]` to be greater than a certain number.
*/
def waitUntil(p: A => Boolean): F[Unit]
Copy link
Member

Choose a reason for hiding this comment

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

Since Signal isn't sealed isn't adding this method a breaking change? :(

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah...that sucks

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add it to SignalOps and that should fix it I think

Copy link
Member

Choose a reason for hiding this comment

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

Does it need to go on SignalOps? You could just put that default implementation and the Concurrent constraint directly here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I could yeah, I guess I just went with how map is implemented. @mpilquist opinions?

Copy link
Member

Choose a reason for hiding this comment

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

No strong ones

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I found a clear justification for having it as an instance method: scaladoc friendliness. I think map has a similar problem, but then you'd have the question of whether removing SignalOps entirely constitutes source breakage or not, so I'll punt on map for now

Copy link
Member

Choose a reason for hiding this comment

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

We can keep SignalOps deprecated, just remove the implicit modifier. So there's no source-breakage but the map on Signal will clearly take precedence.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll leave that for a potential future PR

* to change, or waiting for the value of the `Signal` of an
* ordered `Stream[IO, Int]` to be greater than a certain number.
*/
def waitUntil(p: A => Boolean)(implicit F: Concurrent[F]): F[Unit] =
Copy link
Contributor

@diesalbla diesalbla Feb 5, 2022

Choose a reason for hiding this comment

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

Apart from the question of stability discussed in the comment, that mentions that the signal should be such that a "positive" answer can be observed for some minimal time, could there be a problem here for efficiency.

Some Signals can change very frequently. If it does, there could be no limit to the number of values that self.discrete would emit. If so, could the .compile.drain result in a fiber that could keep running and exhaust CPU? If so, perhaps it could help if this method took a delay parameter, a FiniteDuration, so as to limit the sampling frequency on this signal.

Copy link
Collaborator Author

@SystemFw SystemFw Feb 6, 2022

Choose a reason for hiding this comment

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

mm I think I disagree, the same concern would apply to everything that uses a Signal (e.g. pauseWhen) , forcing this noncompositional sampling parameter everywhere, and potentially slowing reaction times for the vastly more common case where this isn't a concern. Furthermore, in practice this is only a problem when using continuous , not discrete: discrete cannot change any faster than the source, which means that if discrete is changing too fast for your CPU, the source is also changing too fast, and so you already have a problem, and you have to solve at the source (e.g. with debounce). continuous does have this problem because it changes (~infinitely) faster then the source, as do things like Stream.repeatEval(queue.tryTake).unNone.

@SystemFw SystemFw closed this Feb 6, 2022
@SystemFw SystemFw reopened this Feb 6, 2022
@SystemFw SystemFw merged commit ba05de9 into typelevel:main Feb 6, 2022
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.

4 participants