Skip to content

Commit 15c7d0f

Browse files
committed
Mark Flow declarations as experimental
1 parent d5478b6 commit 15c7d0f

File tree

17 files changed

+64
-59
lines changed

17 files changed

+64
-59
lines changed

kotlinx-coroutines-core/common/src/Annotations.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ import kotlinx.coroutines.flow.Flow
1818
public annotation class ExperimentalCoroutinesApi
1919

2020
/**
21-
* Marks all [Flow] declarations as a feature preview to indicate that [Flow] is still experimental and has a 'preview' status.
21+
* Marks [Flow]-related API as a feature preview.
2222
*
2323
* Flow preview has **no** backward compatibility guarantees, including both binary and source compatibility.
2424
* Its API and semantics can and will be changed in next releases.
2525
*
2626
* Feature preview can be used to evaluate its real-world strengths and weaknesses, gather and provide feedback.
2727
* According to the feedback, [Flow] will be refined on its road to stabilization and promotion to a stable API.
28+
*
29+
* The best way to speed up preview feature promotion is providing the feedback on the feature.
2830
*/
2931
@MustBeDocumented
3032
@Retention(value = AnnotationRetention.BINARY)

kotlinx-coroutines-core/common/src/flow/Builders.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ import kotlin.jvm.*
4444
* ```
4545
* If you want to switch the context of execution of a flow, use the [flowOn] operator.
4646
*/
47-
@FlowPreview
47+
@ExperimentalCoroutinesApi
4848
public fun <T> flow(@BuilderInference block: suspend FlowCollector<T>.() -> Unit): Flow<T> {
4949
return object : Flow<T> {
5050
override suspend fun collect(collector: FlowCollector<T>) {
@@ -57,7 +57,6 @@ public fun <T> flow(@BuilderInference block: suspend FlowCollector<T>.() -> Unit
5757
* An analogue of the [flow] builder that does not check the context of execution of the resulting flow.
5858
* Used in our own operators where we trust the context of invocations.
5959
*/
60-
@FlowPreview
6160
@PublishedApi
6261
internal inline fun <T> unsafeFlow(@BuilderInference crossinline block: suspend FlowCollector<T>.() -> Unit): Flow<T> {
6362
return object : Flow<T> {
@@ -91,7 +90,7 @@ public fun <T> (suspend () -> T).asFlow(): Flow<T> = unsafeFlow {
9190
/**
9291
* Creates a flow that produces values from the given iterable.
9392
*/
94-
@FlowPreview
93+
@ExperimentalCoroutinesApi
9594
public fun <T> Iterable<T>.asFlow(): Flow<T> = unsafeFlow {
9695
forEach { value ->
9796
emit(value)
@@ -101,7 +100,7 @@ public fun <T> Iterable<T>.asFlow(): Flow<T> = unsafeFlow {
101100
/**
102101
* Creates a flow that produces values from the given iterable.
103102
*/
104-
@FlowPreview
103+
@ExperimentalCoroutinesApi
105104
public fun <T> Iterator<T>.asFlow(): Flow<T> = unsafeFlow {
106105
forEach { value ->
107106
emit(value)
@@ -111,7 +110,7 @@ public fun <T> Iterator<T>.asFlow(): Flow<T> = unsafeFlow {
111110
/**
112111
* Creates a flow that produces values from the given sequence.
113112
*/
114-
@FlowPreview
113+
@ExperimentalCoroutinesApi
115114
public fun <T> Sequence<T>.asFlow(): Flow<T> = unsafeFlow {
116115
forEach { value ->
117116
emit(value)
@@ -121,7 +120,7 @@ public fun <T> Sequence<T>.asFlow(): Flow<T> = unsafeFlow {
121120
/**
122121
* Creates a flow that produces values from the given array of elements.
123122
*/
124-
@FlowPreview
123+
@ExperimentalCoroutinesApi
125124
public fun <T> flowOf(vararg elements: T): Flow<T> = unsafeFlow {
126125
for (element in elements) {
127126
emit(element)
@@ -131,7 +130,7 @@ public fun <T> flowOf(vararg elements: T): Flow<T> = unsafeFlow {
131130
/**
132131
* Creates flow that produces a given [value].
133132
*/
134-
@FlowPreview
133+
@ExperimentalCoroutinesApi
135134
public fun <T> flowOf(value: T): Flow<T> = unsafeFlow {
136135
/*
137136
* Implementation note: this is just an "optimized" overload of flowOf(vararg)
@@ -143,7 +142,7 @@ public fun <T> flowOf(value: T): Flow<T> = unsafeFlow {
143142
/**
144143
* Returns an empty flow.
145144
*/
146-
@FlowPreview
145+
@ExperimentalCoroutinesApi
147146
public fun <T> emptyFlow(): Flow<T> = EmptyFlow
148147

149148
private object EmptyFlow : Flow<Nothing> {
@@ -153,7 +152,7 @@ private object EmptyFlow : Flow<Nothing> {
153152
/**
154153
* Creates a flow that produces values from the given array.
155154
*/
156-
@FlowPreview
155+
@ExperimentalCoroutinesApi
157156
public fun <T> Array<T>.asFlow(): Flow<T> = unsafeFlow {
158157
forEach { value ->
159158
emit(value)
@@ -163,7 +162,7 @@ public fun <T> Array<T>.asFlow(): Flow<T> = unsafeFlow {
163162
/**
164163
* Creates flow that produces values from the given array.
165164
*/
166-
@FlowPreview
165+
@ExperimentalCoroutinesApi
167166
public fun IntArray.asFlow(): Flow<Int> = unsafeFlow {
168167
forEach { value ->
169168
emit(value)
@@ -173,7 +172,7 @@ public fun IntArray.asFlow(): Flow<Int> = unsafeFlow {
173172
/**
174173
* Creates flow that produces values from the given array.
175174
*/
176-
@FlowPreview
175+
@ExperimentalCoroutinesApi
177176
public fun LongArray.asFlow(): Flow<Long> = unsafeFlow {
178177
forEach { value ->
179178
emit(value)
@@ -183,7 +182,7 @@ public fun LongArray.asFlow(): Flow<Long> = unsafeFlow {
183182
/**
184183
* Creates flow that produces values from the given range.
185184
*/
186-
@FlowPreview
185+
@ExperimentalCoroutinesApi
187186
public fun IntRange.asFlow(): Flow<Int> = unsafeFlow {
188187
forEach { value ->
189188
emit(value)
@@ -193,7 +192,7 @@ public fun IntRange.asFlow(): Flow<Int> = unsafeFlow {
193192
/**
194193
* Creates flow that produces values from the given range.
195194
*/
196-
@FlowPreview
195+
@ExperimentalCoroutinesApi
197196
public fun LongRange.asFlow(): Flow<Long> = flow {
198197
forEach { value ->
199198
emit(value)
@@ -262,7 +261,7 @@ public fun <T> flowViaChannel(
262261
* }
263262
* ```
264263
*/
265-
@FlowPreview
264+
@ExperimentalCoroutinesApi
266265
public fun <T> channelFlow(@BuilderInference block: suspend ProducerScope<T>.() -> Unit): Flow<T> =
267266
ChannelFlowBuilder(block)
268267

@@ -310,6 +309,7 @@ public fun <T> channelFlow(@BuilderInference block: suspend ProducerScope<T>.()
310309
* ```
311310
*/
312311
@Suppress("NOTHING_TO_INLINE")
312+
@ExperimentalCoroutinesApi
313313
public inline fun <T> callbackFlow(@BuilderInference noinline block: suspend ProducerScope<T>.() -> Unit): Flow<T> =
314314
channelFlow(block)
315315

kotlinx-coroutines-core/common/src/flow/Flow.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ import kotlinx.coroutines.*
109109
* Flow is [Reactive Streams](http://www.reactive-streams.org/) compliant, you can safely interop it with
110110
* reactive streams using [Flow.asPublisher] and [Publisher.asFlow] from kotlinx-coroutines-reactive module.
111111
*/
112-
@FlowPreview
112+
@ExperimentalCoroutinesApi
113113
public interface Flow<out T> {
114114

115115
/**

kotlinx-coroutines-core/common/src/flow/FlowCollector.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import kotlinx.coroutines.*
1313
* This interface should usually not be implemented directly, but rather used as a receiver in a [flow] builder when implementing a custom operator.
1414
* Implementations of this interface are not thread-safe.
1515
*/
16-
@FlowPreview
16+
@ExperimentalCoroutinesApi
1717
public interface FlowCollector<in T> {
1818

1919
/**

kotlinx-coroutines-core/common/src/flow/operators/Context.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ import kotlin.jvm.*
104104
* [RENDEZVOUS][Channel.RENDEZVOUS], [UNLIMITED][Channel.UNLIMITED] or a non-negative value indicating
105105
* an explicitly requested size.
106106
*/
107-
@FlowPreview
107+
@ExperimentalCoroutinesApi
108108
public fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T> {
109109
require(capacity >= 0 || capacity == BUFFERED || capacity == CONFLATED) {
110110
"Buffer size should be non-negative, BUFFERED, or CONFLATED, but was $capacity"
@@ -147,7 +147,7 @@ public fun <T> Flow<T>.buffer(capacity: Int = BUFFERED): Flow<T> {
147147
* always fused so that only one properly configured channel is used for execution.
148148
* **Conflation takes precedence over `buffer()` calls with any other capacity.**
149149
*/
150-
@FlowPreview
150+
@ExperimentalCoroutinesApi
151151
public fun <T> Flow<T>.conflate(): Flow<T> = buffer(CONFLATED)
152152

153153
/**
@@ -194,7 +194,7 @@ public fun <T> Flow<T>.conflate(): Flow<T> = buffer(CONFLATED)
194194
*
195195
* @throws [IllegalArgumentException] if provided context contains [Job] instance.
196196
*/
197-
@FlowPreview
197+
@ExperimentalCoroutinesApi
198198
public fun <T> Flow<T>.flowOn(context: CoroutineContext): Flow<T> {
199199
checkFlowContext(context)
200200
return when {

kotlinx-coroutines-core/common/src/flow/operators/Delay.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import kotlinx.coroutines.flow.unsafeFlow as flow
1717
/**
1818
* Delays the emission of values from this flow for the given [timeMillis].
1919
*/
20-
@FlowPreview
20+
@ExperimentalCoroutinesApi
2121
public fun <T> Flow<T>.delayFlow(timeMillis: Long): Flow<T> = flow {
2222
delay(timeMillis)
2323
collect(this@flow)
@@ -26,7 +26,7 @@ public fun <T> Flow<T>.delayFlow(timeMillis: Long): Flow<T> = flow {
2626
/**
2727
* Delays each element emitted by the given flow for the given [timeMillis].
2828
*/
29-
@FlowPreview
29+
@ExperimentalCoroutinesApi
3030
public fun <T> Flow<T>.delayEach(timeMillis: Long): Flow<T> = flow {
3131
collect { value ->
3232
delay(timeMillis)
@@ -58,6 +58,7 @@ public fun <T> Flow<T>.delayEach(timeMillis: Long): Flow<T> = flow {
5858
* Note that the resulting flow does not emit anything as long as the original flow emits
5959
* items faster than every [timeoutMillis] milliseconds.
6060
*/
61+
@FlowPreview
6162
public fun <T> Flow<T>.debounce(timeoutMillis: Long): Flow<T> {
6263
require(timeoutMillis > 0) { "Debounce timeout should be positive" }
6364
return scopedFlow { downstream ->
@@ -109,6 +110,7 @@ public fun <T> Flow<T>.debounce(timeoutMillis: Long): Flow<T> {
109110
*
110111
* Note that the latest element is not emitted if it does not fit into the sampling window.
111112
*/
113+
@FlowPreview
112114
public fun <T> Flow<T>.sample(periodMillis: Long): Flow<T> {
113115
require(periodMillis > 0) { "Sample period should be positive" }
114116
return scopedFlow { downstream ->

kotlinx-coroutines-core/common/src/flow/operators/Distinct.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import kotlinx.coroutines.flow.unsafeFlow as flow
1515
/**
1616
* Returns flow where all subsequent repetitions of the same value are filtered out.
1717
*/
18-
@FlowPreview
18+
@ExperimentalCoroutinesApi
1919
public fun <T> Flow<T>.distinctUntilChanged(): Flow<T> = distinctUntilChangedBy { it }
2020

2121
/**

kotlinx-coroutines-core/common/src/flow/operators/Limit.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import kotlinx.coroutines.flow.unsafeFlow as flow
1717
* Returns a flow that ignores first [count] elements.
1818
* Throws [IllegalArgumentException] if [count] is negative.
1919
*/
20-
@FlowPreview
20+
@ExperimentalCoroutinesApi
2121
public fun <T> Flow<T>.drop(count: Int): Flow<T> {
2222
require(count >= 0) { "Drop count should be non-negative, but had $count" }
2323
return flow {
@@ -31,7 +31,7 @@ public fun <T> Flow<T>.drop(count: Int): Flow<T> {
3131
/**
3232
* Returns a flow containing all elements except first elements that satisfy the given predicate.
3333
*/
34-
@FlowPreview
34+
@ExperimentalCoroutinesApi
3535
public fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T> = flow {
3636
var matched = false
3737
collect { value ->
@@ -49,7 +49,7 @@ public fun <T> Flow<T>.dropWhile(predicate: suspend (T) -> Boolean): Flow<T> = f
4949
* When [count] elements are consumed, the original flow is cancelled.
5050
* Throws [IllegalArgumentException] if [count] is not positive.
5151
*/
52-
@FlowPreview
52+
@ExperimentalCoroutinesApi
5353
public fun <T> Flow<T>.take(count: Int): Flow<T> {
5454
require(count > 0) { "Requested element count $count should be positive" }
5555
return flow {
@@ -70,7 +70,7 @@ public fun <T> Flow<T>.take(count: Int): Flow<T> {
7070
/**
7171
* Returns a flow that contains first elements satisfying the given [predicate].
7272
*/
73-
@FlowPreview
73+
@ExperimentalCoroutinesApi
7474
public fun <T> Flow<T>.takeWhile(predicate: suspend (T) -> Boolean): Flow<T> = flow {
7575
try {
7676
collect { value ->

kotlinx-coroutines-core/common/src/flow/operators/Merge.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public fun <T> Flow<Flow<T>>.flattenMerge(concurrency: Int = DEFAULT_CONCURRENCY
124124
* ```
125125
* produces `aa bb b_last`
126126
*/
127-
@FlowPreview
127+
@ExperimentalCoroutinesApi
128128
public fun <T, R> Flow<T>.switchMap(transform: suspend (value: T) -> Flow<R>): Flow<R> = scopedFlow { downstream ->
129129
var previousFlow: Job? = null
130130
collect { value ->

kotlinx-coroutines-core/common/src/flow/operators/Transform.kt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import kotlinx.coroutines.flow.unsafeFlow as flow
2727
* }
2828
* ```
2929
*/
30-
@FlowPreview
30+
@ExperimentalCoroutinesApi
3131
public inline fun <T, R> Flow<T>.transform(@BuilderInference crossinline transform: suspend FlowCollector<R>.(value: T) -> Unit): Flow<R> {
3232
return flow {
3333
collect { value ->
@@ -40,7 +40,7 @@ public inline fun <T, R> Flow<T>.transform(@BuilderInference crossinline transfo
4040
/**
4141
* Returns a flow containing only values of the original flow that matches the given [predicate].
4242
*/
43-
@FlowPreview
43+
@ExperimentalCoroutinesApi
4444
public inline fun <T> Flow<T>.filter(crossinline predicate: suspend (T) -> Boolean): Flow<T> = flow {
4545
collect { value ->
4646
if (predicate(value)) return@collect emit(value)
@@ -50,7 +50,7 @@ public inline fun <T> Flow<T>.filter(crossinline predicate: suspend (T) -> Boole
5050
/**
5151
* Returns a flow containing only values of the original flow that do not match the given [predicate].
5252
*/
53-
@FlowPreview
53+
@ExperimentalCoroutinesApi
5454
public inline fun <T> Flow<T>.filterNot(crossinline predicate: suspend (T) -> Boolean): Flow<T> = flow {
5555
collect { value ->
5656
if (!predicate(value)) return@collect emit(value)
@@ -60,30 +60,30 @@ public inline fun <T> Flow<T>.filterNot(crossinline predicate: suspend (T) -> Bo
6060
/**
6161
* Returns a flow containing only values that are instances of specified type [R].
6262
*/
63-
@FlowPreview
63+
@ExperimentalCoroutinesApi
6464
@Suppress("UNCHECKED_CAST")
6565
public inline fun <reified R> Flow<*>.filterIsInstance(): Flow<R> = filter { it is R } as Flow<R>
6666

6767
/**
6868
* Returns a flow containing only values of the original flow that are not null.
6969
*/
70-
@FlowPreview
70+
@ExperimentalCoroutinesApi
7171
public fun <T: Any> Flow<T?>.filterNotNull(): Flow<T> = flow<T> {
7272
collect { value -> if (value != null) return@collect emit(value) }
7373
}
7474

7575
/**
7676
* Returns a flow containing the results of applying the given [transform] function to each value of the original flow.
7777
*/
78-
@FlowPreview
78+
@ExperimentalCoroutinesApi
7979
public inline fun <T, R> Flow<T>.map(crossinline transform: suspend (value: T) -> R): Flow<R> = transform { value ->
8080
return@transform emit(transform(value))
8181
}
8282

8383
/**
8484
* Returns a flow that contains only non-null results of applying the given [transform] function to each value of the original flow.
8585
*/
86-
@FlowPreview
86+
@ExperimentalCoroutinesApi
8787
public inline fun <T, R: Any> Flow<T>.mapNotNull(crossinline transform: suspend (value: T) -> R?): Flow<R> = transform { value ->
8888
val transformed = transform(value) ?: return@transform
8989
return@transform emit(transformed)
@@ -92,7 +92,7 @@ public inline fun <T, R: Any> Flow<T>.mapNotNull(crossinline transform: suspend
9292
/**
9393
* Returns a flow which performs the given [action] on each value of the original flow.
9494
*/
95-
@FlowPreview
95+
@ExperimentalCoroutinesApi
9696
public fun <T> Flow<T>.onEach(action: suspend (T) -> Unit): Flow<T> = flow {
9797
collect { value ->
9898
action(value)
@@ -109,7 +109,7 @@ public fun <T> Flow<T>.onEach(action: suspend (T) -> Unit): Flow<T> = flow {
109109
* ```
110110
* will produce `[], [1], [1, 2], [1, 2, 3]]`.
111111
*/
112-
@FlowPreview
112+
@ExperimentalCoroutinesApi
113113
public fun <T, R> Flow<T>.scan(initial: R, @BuilderInference operation: suspend (accumulator: R, value: T) -> R): Flow<R> = flow {
114114
var accumulator: R = initial
115115
emit(accumulator)
@@ -130,7 +130,7 @@ public fun <T, R> Flow<T>.scan(initial: R, @BuilderInference operation: suspend
130130
* ```
131131
* will produce `[1, 3, 6, 10]`
132132
*/
133-
@FlowPreview
133+
@ExperimentalCoroutinesApi
134134
public fun <T> Flow<T>.scanReduce(operation: suspend (accumulator: T, value: T) -> T): Flow<T> = flow {
135135
var accumulator: Any? = NULL
136136
collect { value ->

0 commit comments

Comments
 (0)