File tree 2 files changed +19
-4
lines changed
kotlinx-coroutines-core/common
2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
@file:JvmMultifileClass
5
5
@file:JvmName(" ChannelsKt" )
6
6
@file:Suppress(" DEPRECATION_ERROR" )
7
+ @file:OptIn(ExperimentalContracts ::class )
7
8
8
9
package kotlinx.coroutines.channels
9
10
10
11
import kotlinx.coroutines.*
11
12
import kotlinx.coroutines.selects.*
13
+ import kotlin.contracts.*
12
14
import kotlin.coroutines.*
13
15
import kotlin.jvm.*
14
16
@@ -164,6 +166,9 @@ public fun consumesAll(vararg channels: ReceiveChannel<*>): CompletionHandler =
164
166
* The operation is _terminal_.
165
167
*/
166
168
public inline fun <E , R > ReceiveChannel<E>.consume (block : ReceiveChannel <E >.() -> R ): R {
169
+ contract {
170
+ callsInPlace(block, InvocationKind .EXACTLY_ONCE )
171
+ }
167
172
var cause: Throwable ? = null
168
173
try {
169
174
return block()
Original file line number Diff line number Diff line change 1
1
/*
2
- * Copyright 2016-2020 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2021 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
5
package kotlinx.coroutines
6
6
7
+ import kotlinx.coroutines.channels.*
7
8
import kotlinx.coroutines.selects.*
8
9
import kotlin.test.*
9
10
@@ -44,9 +45,18 @@ class BuilderContractsTest : TestBase() {
44
45
Job ().apply { complete() }.onJoin {}
45
46
}
46
47
consume(s)
48
+
49
+
50
+ val ch: Int
51
+ val i = Channel <Int >()
52
+ i.consume {
53
+ ch = 321
54
+ }
55
+ consume(ch)
47
56
}
48
57
49
58
private fun consume (a : Int ) {
50
- a.hashCode() // BE codegen verification
59
+ assertNotEquals(0 , a)
60
+ assertEquals(a.hashCode(), a)
51
61
}
52
- }
62
+ }
You can’t perform that action at this time.
0 commit comments