@@ -11,6 +11,7 @@ import kotlinx.coroutines.*
11
11
import kotlinx.coroutines.channels.*
12
12
import kotlinx.coroutines.channels.Channel.Factory.BUFFERED
13
13
import kotlinx.coroutines.flow.internal.*
14
+ import kotlinx.coroutines.flow.internal.unsafeFlow as flow
14
15
import kotlin.coroutines.*
15
16
import kotlin.jvm.*
16
17
@@ -53,24 +54,11 @@ private class SafeFlow<T>(private val block: suspend FlowCollector<T>.() -> Unit
53
54
}
54
55
}
55
56
56
- /* *
57
- * An analogue of the [flow] builder that does not check the context of execution of the resulting flow.
58
- * Used in our own operators where we trust the context of invocations.
59
- */
60
- @PublishedApi
61
- internal inline fun <T > unsafeFlow (@BuilderInference crossinline block : suspend FlowCollector <T >.() -> Unit ): Flow <T > {
62
- return object : Flow <T > {
63
- override suspend fun collect (collector : FlowCollector <T >) {
64
- collector.block()
65
- }
66
- }
67
- }
68
-
69
57
/* *
70
58
* Creates a flow that produces a single value from the given functional type.
71
59
*/
72
60
@FlowPreview
73
- public fun <T > (() -> T ).asFlow(): Flow <T > = unsafeFlow {
61
+ public fun <T > (() -> T ).asFlow(): Flow <T > = flow {
74
62
emit(invoke())
75
63
}
76
64
@@ -83,14 +71,14 @@ public fun <T> (() -> T).asFlow(): Flow<T> = unsafeFlow {
83
71
* ```
84
72
*/
85
73
@FlowPreview
86
- public fun <T > (suspend () -> T ).asFlow(): Flow <T > = unsafeFlow {
74
+ public fun <T > (suspend () -> T ).asFlow(): Flow <T > = flow {
87
75
emit(invoke())
88
76
}
89
77
90
78
/* *
91
79
* Creates a flow that produces values from the given iterable.
92
80
*/
93
- public fun <T > Iterable<T>.asFlow (): Flow <T > = unsafeFlow {
81
+ public fun <T > Iterable<T>.asFlow (): Flow <T > = flow {
94
82
forEach { value ->
95
83
emit(value)
96
84
}
@@ -99,7 +87,7 @@ public fun <T> Iterable<T>.asFlow(): Flow<T> = unsafeFlow {
99
87
/* *
100
88
* Creates a flow that produces values from the given iterable.
101
89
*/
102
- public fun <T > Iterator<T>.asFlow (): Flow <T > = unsafeFlow {
90
+ public fun <T > Iterator<T>.asFlow (): Flow <T > = flow {
103
91
forEach { value ->
104
92
emit(value)
105
93
}
@@ -108,7 +96,7 @@ public fun <T> Iterator<T>.asFlow(): Flow<T> = unsafeFlow {
108
96
/* *
109
97
* Creates a flow that produces values from the given sequence.
110
98
*/
111
- public fun <T > Sequence<T>.asFlow (): Flow <T > = unsafeFlow {
99
+ public fun <T > Sequence<T>.asFlow (): Flow <T > = flow {
112
100
forEach { value ->
113
101
emit(value)
114
102
}
@@ -117,7 +105,7 @@ public fun <T> Sequence<T>.asFlow(): Flow<T> = unsafeFlow {
117
105
/* *
118
106
* Creates a flow that produces values from the given array of elements.
119
107
*/
120
- public fun <T > flowOf (vararg elements : T ): Flow <T > = unsafeFlow {
108
+ public fun <T > flowOf (vararg elements : T ): Flow <T > = flow {
121
109
for (element in elements) {
122
110
emit(element)
123
111
}
@@ -126,7 +114,7 @@ public fun <T> flowOf(vararg elements: T): Flow<T> = unsafeFlow {
126
114
/* *
127
115
* Creates flow that produces a given [value].
128
116
*/
129
- public fun <T > flowOf (value : T ): Flow <T > = unsafeFlow {
117
+ public fun <T > flowOf (value : T ): Flow <T > = flow {
130
118
/*
131
119
* Implementation note: this is just an "optimized" overload of flowOf(vararg)
132
120
* which significantly reduce the footprint of widespread single-value flows.
@@ -146,7 +134,7 @@ private object EmptyFlow : Flow<Nothing> {
146
134
/* *
147
135
* Creates a flow that produces values from the given array.
148
136
*/
149
- public fun <T > Array<T>.asFlow (): Flow <T > = unsafeFlow {
137
+ public fun <T > Array<T>.asFlow (): Flow <T > = flow {
150
138
forEach { value ->
151
139
emit(value)
152
140
}
@@ -155,7 +143,7 @@ public fun <T> Array<T>.asFlow(): Flow<T> = unsafeFlow {
155
143
/* *
156
144
* Creates flow that produces values from the given array.
157
145
*/
158
- public fun IntArray.asFlow (): Flow <Int > = unsafeFlow {
146
+ public fun IntArray.asFlow (): Flow <Int > = flow {
159
147
forEach { value ->
160
148
emit(value)
161
149
}
@@ -164,7 +152,7 @@ public fun IntArray.asFlow(): Flow<Int> = unsafeFlow {
164
152
/* *
165
153
* Creates flow that produces values from the given array.
166
154
*/
167
- public fun LongArray.asFlow (): Flow <Long > = unsafeFlow {
155
+ public fun LongArray.asFlow (): Flow <Long > = flow {
168
156
forEach { value ->
169
157
emit(value)
170
158
}
@@ -173,7 +161,7 @@ public fun LongArray.asFlow(): Flow<Long> = unsafeFlow {
173
161
/* *
174
162
* Creates flow that produces values from the given range.
175
163
*/
176
- public fun IntRange.asFlow (): Flow <Int > = unsafeFlow {
164
+ public fun IntRange.asFlow (): Flow <Int > = flow {
177
165
forEach { value ->
178
166
emit(value)
179
167
}
0 commit comments