-
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
Flow size- and time-based chunked #2378
base: develop
Are you sure you want to change the base?
Flow size- and time-based chunked #2378
Conversation
Merge with parent project
Sync develop with parent project
Merge with parent project
Merge with parent project
Please, please, read contributing guidelines first: https://github.com/Kotlin/kotlinx.coroutines/blob/master/CONTRIBUTING.md If you introduce any new public APIs:
|
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 PR does not follow contributing guidelines: it has no docs and it does not have a community-discussed design.
Sure. I have initiated discussion in #1302 (comment) Commits with lacking docs, annotations and api dump will follow shortly. |
I am converting this PR to Draft until we reach some outcome in #1302 discussion. |
Merge with parent project
Merge with parent repo
…ow-time-based-chunked # Conflicts: # kotlinx-coroutines-core/common/test/flow/operators/ChunkedTest.kt
@@ -7,7 +7,7 @@ | |||
[![Slack channel](https://img.shields.io/badge/chat-slack-green.svg?logo=slack)](https://kotlinlang.slack.com/messages/coroutines/) |
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 file has been apparently changed on master but not on develop - with PR: Improve readability. #2563
I have:
|
Hi :) Are there any updates? The operator looks very handy and useful. |
It looks to me that using For example, if one tries to "chunk" mouse clicks, the code in Also, in the scenario above we probably want to buffer events while user keeps clicking and emit that buffer only when user stops. I see 2 options how to "chunk" here. We may want to a) emit something right away and cancel later as |
val elements = produce<T>(capacity = maxSize) { | ||
collect { element -> | ||
val hasCapacity = channel.trySend(element).isSuccess | ||
if (!hasCapacity) { |
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.
what do you think about size instead of maxSize like SizedBased? when channel reached to size it should be emit
Add two operators for size- and time-based chunking of Flows. Targets issues: #1290
#1302
New operators:
public fun <T> Flow<T>.chunked(maxSize: Int, minSize: Int = 1)
public fun <T> Flow<T>.chunked( chunkDuration: Duration, minSize: Int = 1, maxSize: Int = NO_MAXIMUM ): Flow<List<T>>
public fun <T> Flow<T>.chunked( chunkDurationMs: Long, minSize: Int = 1, maxSize: Int = NO_MAXIMUM ): Flow<List<T>>
Time based impl:
To be added: