@@ -3,6 +3,9 @@ package dev.silenium.libs.flows.impl
3
3
import dev.silenium.libs.flows.api.*
4
4
import kotlinx.coroutines.*
5
5
import kotlinx.coroutines.flow.map
6
+ import kotlin.contracts.ExperimentalContracts
7
+ import kotlin.contracts.InvocationKind
8
+ import kotlin.contracts.contract
6
9
import kotlin.coroutines.CoroutineContext
7
10
import kotlin.reflect.KClass
8
11
@@ -147,10 +150,14 @@ internal fun FlowGraph.builder() = FlowGraphConfigScopeImpl(this)
147
150
* @see FlowGraph
148
151
* @see CoroutineContext
149
152
*/
153
+ @OptIn(ExperimentalContracts ::class )
150
154
suspend fun FlowGraph (
151
155
coroutineContext : CoroutineContext = Dispatchers .Default ,
152
156
block : FlowGraphConfigScope .() -> Unit ,
153
- ): FlowGraph = FlowGraphImpl (coroutineContext).builder().apply (block).configure().getOrThrow()
157
+ ): FlowGraph {
158
+ contract { callsInPlace(block, InvocationKind .EXACTLY_ONCE ) }
159
+ return FlowGraphImpl (coroutineContext).builder().apply (block).configure().getOrThrow()
160
+ }
154
161
155
162
/* *
156
163
* Creates a new [FlowGraph] with the given [coroutineScope] and [block] configuration.
@@ -163,7 +170,11 @@ suspend fun FlowGraph(
163
170
* @see FlowGraph
164
171
* @see CoroutineScope
165
172
*/
173
+ @OptIn(ExperimentalContracts ::class )
166
174
suspend fun FlowGraph (
167
175
coroutineScope : CoroutineScope ,
168
176
block : FlowGraphConfigScope .() -> Unit ,
169
- ): FlowGraph = FlowGraphImpl (coroutineScope).builder().apply (block).configure().getOrThrow()
177
+ ): FlowGraph {
178
+ contract { callsInPlace(block, InvocationKind .EXACTLY_ONCE ) }
179
+ return FlowGraphImpl (coroutineScope).builder().apply (block).configure().getOrThrow()
180
+ }
0 commit comments