-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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 timeout operator to Flow #2624
Comments
I'm not against such operator at all (on the contrary) but I am not sure this specific use case is a good example for it. This use case seems to need the timeout on the consumer side, and for this I wonder why a I would imagine that |
To give a more specific use-case, I'll go with one for Android: With GPS location on Android, it's not always guaranteed that location events come in at the desired interval (it could vary based on the environment). It's even possible that no GPS location will come in if there is no clear signal. However, even if no signal is available, the GPS radio will remain on, draining battery power. To prevent this, you would use a timeout on the location events coming in, and if there are none after a period of time, turn off the radio. An example of what a location emitting flow would look like (without a timeout):
Every consumer of this flow could have a different requirement for what they consider to be a timeout event. One example is that these locations may not be accurate enough. In this case, a filter would be added to the flow, which filters out inaccurate locations.
If locations are emitted regularly until we get to a bad signal area, where new locations have now become inaccurate enough to be filtered, I would want a timeout to occur if I received no location for the last 10 seconds. Adding the timeout to the producer wouldn't work, as it could be emitting location data regularly, even though they are filtered downstream. Using a |
The requirement seems reasonable, but the solution doesn't seem to help with this problem, as the upstream would probably not be affected by the timeout at all (at least in the PR, I didn't see any mechanism to re-collect the upstream flow on timeout).
Exactly, and that is the point: cancel the flow so that the producer can clean up resources. If you want to re-subscribe later, you can always re-collect that flow. In any case, in this example I don't believe there is a way for you to know that new valid locations are available again after a timeout without keeping the location service on in the first place. Or am I missing something? |
In the PR, an exception is being thrown, which would close the the entire flow, unless the flow was a
The
Well... I could leave the radio on, but users would be upset for the battery drain. :-) In the above example, if I got the timeout trigger, I would probably setup a different trigger (timer, geofence, activity recognition) to notify for a retry. |
Actually, this conversation is showing me a bug in my implementation. This breaks the |
What I thought was a bug: If the timeout emits an item instead of throwing an exception, the It wasn't a bug, but I did see I was misusing the |
Ok, I think I had missed the initial intent of the
Oh, right. Obvious overlook on my part, sorry about that. |
Sorry for being late for the party and thanks for the productive discussion! The overall idea seems worth integrating (especially now when such resources can be shared via The only thing that concerns me is the naming -- it's easy to confuse with |
I had a similar concern about the naming when I created the PR for this, but I figured that given this would be an operator on If you need an argument in your design meetings in favor of |
@qwwdfsad any update on this? |
Not trying to bug too much on this issue, just a small nudge to get this back in mind for folks, @qwwdfsad. |
Sorry folks, we are stretched thin right now and cannot really get back to this issue, yet it's something in our "to do in the observable future" radar |
Enhancement: Add
timeout
operator to FlowThis is in response to the updated contribution guidelines, and to push for a
timeout
mechanism for Flow (#2597). Currently, there is no easy way to timeout a flow if the upstream takes too long to produce an event.Use case:
A flow when collected may not always emit items at a regular interval. If this flow is using some resource intensive process or enabling some hardware, leaving it active with no events for an extended period of time is wasteful. By having a timeout operator on the flow if no events have emitted, it allows for creating flows based with a defined timeout strategy, to ensure these resources aren't being accidentally misused.
The text was updated successfully, but these errors were encountered: