kotlinx.coroutines
kotlinx.coroutines copied to clipboard
Add timeout operator to Flow (redux)
This adds functionality similar to the timeout()
in Rx. This invokes a timeout if the upstream flow doesn't emit after the set period of time, with the option to perform a custom action on timeout.
This PR is in support of #2624. One item that was discussed was the name of this new function. I couldn't think of a better one, but I'm not opposed to renaming from timeout()
to something else.
Any update on this PR?
Hi, sorry, this PR eluded me.
We are very careful with time-related API and still not sure how to properly expose it (e.g. https://github.com/Kotlin/kotlinx.coroutines/pull/2745#pullrequestreview-681969186 and https://github.com/Kotlin/kotlinx.coroutines/pull/2738)
We'll use this work as a reference, but we still haven't found a proper chunk of time to get back to it
Thanks for the update!
Regarding the reason from #2745, I understand the concern, but the problem currently is that there is no easy way to shutdown an upstream flow if nothing has been emitted after some period of time, without also shutting down the downstream. What this operator provides does not exist with Flow currently. As mentioned in the issue (https://github.com/Kotlin/kotlinx.coroutines/issues/2624), this operator will be a huge benefit for better handling of resource intensive tasks (ex: GPS emitting on Android, which is battery intensive) when used with a flow.
Let me know if there's anything more I can do to help push this along.
I think this kind of operator is essential,but do need more careful to took in as a stable.api
Also, please change the base branch to develop
and rebase on the latest develop
for the sake of simplicity
@pablobaxter maybe rename to idleTimeout
?
@pablobaxter maybe rename to
idleTimeout
?
@qwwdfsad Thoughts? I know you had a concern about the name of the API as well.
incase there will be something like backpressureTimeout
completionTimeout
etc someday.
I'll return to this PR during the course of next week, no worries here
Sorry for the delay with review -- caught COVID and became even less responsive :(
Sorry for the delay with review -- caught COVID and became even less responsive :(
No worries. I hope you are resting up and taking care of yourself. Get better soon. I'll work on the changes and update accordingly.
Sorry for the delay with review -- caught COVID and became even less responsive :(
No worries. I hope you are resting up and taking care of yourself. Get better soon. I'll work on the changes and update accordingly.
Take good care
Thank you! 👍
Thank you! 👍
Thank you for helping push this along!