-
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 debounce selector #2148
Add debounce selector #2148
Conversation
kotlinx-coroutines-core/common/test/flow/operators/DebounceTest.kt
Outdated
Show resolved
Hide resolved
Hi @fvasco, any updates? |
Hi, @mkano9, If you think there is an issue with the current implementation, please consider to write a consistent test case and file a new issue. |
+1 to this feature. Any progress? |
We've discussed the design aspects of this change in the team. Green light to the addition itself, but here are some minor adjustments that are needed:
Can you please adjust your PR correspondingly? |
Hi @elizarov, thanks for the feedback. I updated the PR. |
@@ -16,7 +16,7 @@ import kotlin.time.* | |||
|
|||
/** | |||
* Returns a flow that mirrors the original flow, but filters out values | |||
* that are followed by the newer values within the given [timeout][timeoutMillis]. | |||
* that are followed by the newer values within the given [timeoutMillis]. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, leave this part of the docs as before (it is consistent with how sample
is documented, too)
* | ||
* @param timeoutMillisSelector [T] is the emitted value and the return value is timeout in milliseconds. | ||
*/ | ||
@ExperimentalTime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This one should not have @ExperimentalTime
annotation, but there should be another version with (T) -> Duration
selector that has one.
val timeoutMillis = timeoutMillisSelector(unboxedValue) | ||
require(timeoutMillis >= 0L) { "Debounce timeout should not be negative" } | ||
// set timeout when lastValue != null | ||
onTimeout(timeoutMillis) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A case with timeoutMillis == 0
should be explicitly optimized here -- emit it immediately instead of installing onTimeout
case.
I accidentally merged with master and made further mess. I opened a new PR #2314 and closing this one. |
Adding support for debounce selector to allow changing debounce time based on the latest emitted value.
Resolves #1216.