@@ -17,16 +17,19 @@ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
17
17
18
18
/* *
19
19
* Name of the property that defines the value of [DEFAULT_CONCURRENCY].
20
+ * This is a preview API and can be changed in a backwards-incompatible manner within a single release.
20
21
*/
21
22
@FlowPreview
22
23
public const val DEFAULT_CONCURRENCY_PROPERTY_NAME : String = " kotlinx.coroutines.flow.defaultConcurrency"
23
24
24
25
/* *
25
26
* Default concurrency limit that is used by [flattenMerge] and [flatMapMerge] operators.
26
27
* It is 16 by default and can be changed on JVM using [DEFAULT_CONCURRENCY_PROPERTY_NAME] property.
28
+ * This is a preview API and can be changed in a backwards-incompatible manner within a single release.
27
29
*/
28
30
@FlowPreview
29
- public val DEFAULT_CONCURRENCY : Int = systemProp(DEFAULT_CONCURRENCY_PROPERTY_NAME ,
31
+ public val DEFAULT_CONCURRENCY : Int = systemProp(
32
+ DEFAULT_CONCURRENCY_PROPERTY_NAME ,
30
33
16 , 1 , Int .MAX_VALUE
31
34
)
32
35
@@ -39,7 +42,7 @@ public val DEFAULT_CONCURRENCY: Int = systemProp(DEFAULT_CONCURRENCY_PROPERTY_NA
39
42
* Note that even though this operator looks very familiar, we discourage its usage in a regular application-specific flows.
40
43
* Most likely, suspending operation in [map] operator will be sufficient and linear transformations are much easier to reason about.
41
44
*/
42
- @FlowPreview
45
+ @ExperimentalCoroutinesApi
43
46
public fun <T , R > Flow<T>.flatMapConcat (transform : suspend (value: T ) -> Flow <R >): Flow <R > =
44
47
map(transform).flattenConcat()
45
48
@@ -63,7 +66,7 @@ public fun <T, R> Flow<T>.flatMapConcat(transform: suspend (value: T) -> Flow<R>
63
66
* @param concurrency controls the number of in-flight flows, at most [concurrency] flows are collected
64
67
* at the same time. By default, it is equal to [DEFAULT_CONCURRENCY].
65
68
*/
66
- @FlowPreview
69
+ @ExperimentalCoroutinesApi
67
70
public fun <T , R > Flow<T>.flatMapMerge (
68
71
concurrency : Int = DEFAULT_CONCURRENCY ,
69
72
transform : suspend (value: T ) -> Flow <R >
@@ -75,7 +78,7 @@ public fun <T, R> Flow<T>.flatMapMerge(
75
78
*
76
79
* Inner flows are collected by this operator *sequentially*.
77
80
*/
78
- @FlowPreview
81
+ @ExperimentalCoroutinesApi
79
82
public fun <T > Flow<Flow<T>>.flattenConcat (): Flow <T > = flow {
80
83
collect { value -> emitAll(value) }
81
84
}
@@ -132,7 +135,7 @@ public fun <T> merge(vararg flows: Flow<T>): Flow<T> = flows.asIterable().merge(
132
135
* @param concurrency controls the number of in-flight flows, at most [concurrency] flows are collected
133
136
* at the same time. By default, it is equal to [DEFAULT_CONCURRENCY].
134
137
*/
135
- @FlowPreview
138
+ @ExperimentalCoroutinesApi
136
139
public fun <T > Flow<Flow<T>>.flattenMerge (concurrency : Int = DEFAULT_CONCURRENCY ): Flow <T > {
137
140
require(concurrency > 0 ) { " Expected positive concurrency level, but had $concurrency " }
138
141
return if (concurrency == 1 ) flattenConcat() else ChannelFlowMerge (this , concurrency)
0 commit comments