@@ -3,6 +3,9 @@ package dev.silenium.libs.flows.impl
33import dev.silenium.libs.flows.api.*
44import kotlinx.coroutines.*
55import kotlinx.coroutines.flow.map
6+ import kotlin.contracts.ExperimentalContracts
7+ import kotlin.contracts.InvocationKind
8+ import kotlin.contracts.contract
69import kotlin.coroutines.CoroutineContext
710import kotlin.reflect.KClass
811
@@ -147,10 +150,14 @@ internal fun FlowGraph.builder() = FlowGraphConfigScopeImpl(this)
147150 * @see FlowGraph
148151 * @see CoroutineContext
149152 */
153+ @OptIn(ExperimentalContracts ::class )
150154suspend fun FlowGraph (
151155 coroutineContext : CoroutineContext = Dispatchers .Default ,
152156 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+ }
154161
155162/* *
156163 * Creates a new [FlowGraph] with the given [coroutineScope] and [block] configuration.
@@ -163,7 +170,11 @@ suspend fun FlowGraph(
163170 * @see FlowGraph
164171 * @see CoroutineScope
165172 */
173+ @OptIn(ExperimentalContracts ::class )
166174suspend fun FlowGraph (
167175 coroutineScope : CoroutineScope ,
168176 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