-
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 sample operator to Flow, which can sample a Flow with the emissions of another Flow #1153
base: develop
Are you sure you want to change the base?
Conversation
Each |
…ted to flows beforehand
@fvasco That makes sense. I removed the channel operator with its unit tests since they can easily be converted to flows. |
…ted to flows beforehand
Can you, please, clarify what is the use-case for |
One simple use case for this operator would be the Refresh Button in Gmail when there's new mails available:
These two flows cannot be:
|
Update cooroutines
# Conflicts: # binary-compatibility-validator/reference-public-api/kotlinx-coroutines-core.txt # kotlinx-coroutines-core/common/src/flow/operators/Delay.kt
- remove old sample implementation - remove old sample unit tests and add them as the new ones
I renamed the operator to Also, I've updated the code to use the new |
- remove old sample implementation - remove old sample unit tests and add them as the new ones
@elizarov does this PR need further improvements? I'm asking since it becomes a stale/conflicting branch after a few days. |
We have not reached consensus yet on whether we should add |
4a49830
to
aff8202
Compare
Update core coroutines
# Conflicts: # kotlinx-coroutines-core/api/kotlinx-coroutines-core.api # kotlinx-coroutines-core/common/src/flow/operators/Delay.kt # kotlinx-coroutines-core/common/test/flow/operators/SampleTest.kt
# Conflicts: # kotlinx-coroutines-core/api/kotlinx-coroutines-core.api
# Conflicts: # kotlinx-coroutines-core/api/kotlinx-coroutines-core.api # kotlinx-coroutines-core/common/src/flow/operators/Delay.kt
@elizarov Since this PR is still open (which is appreciated, after 4 years 😅), I've updated it with master so we can decide on merging or closing it. Just to reiterate this PR's purpose, it generalizes the Thanks. |
The aim of this PR is to bring the ability to
sample
aflow
with the emissions from another flow. I've a extension methods toFlow
:Flow<T>.sampleBy(sampler:ReceiveChannel<R>)
which samples a flow whenever the receive channel emits.Notes:
sampleBy
method with a simpleflow
of an interval.sample(period)
have been added for both the operators (in a new file calledSampleByTest
).sample
, but I thinksampleBy
is more readable/understandable.Example of
sampleBy
with another Flow:produces
0, 2, 4, 6, 8
.