Skip to content

Commit ea4ece3

Browse files
committed
Gracefully icnrease deprecation level on Channel operators instead of removing them, warning was not strict enough
1 parent 993c192 commit ea4ece3

File tree

2 files changed

+210
-192
lines changed

2 files changed

+210
-192
lines changed

benchmarks/src/jmh/kotlin/benchmarks/ChannelSinkBenchmark.kt

+18
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,22 @@ open class ChannelSinkBenchmark {
5050
for (i in start until (start + count))
5151
send(i)
5252
}
53+
54+
// Migrated from deprecated operators, are good only for stressing channels
55+
56+
private fun <E> ReceiveChannel<E>.filter(context: CoroutineContext = Dispatchers.Unconfined, predicate: suspend (E) -> Boolean): ReceiveChannel<E> =
57+
GlobalScope.produce(context, onCompletion = { cancel() }) {
58+
for (e in this@filter) {
59+
if (predicate(e)) send(e)
60+
}
61+
}
62+
63+
private suspend inline fun <E, R> ReceiveChannel<E>.fold(initial: R, operation: (acc: R, E) -> R): R {
64+
var accumulator = initial
65+
consumeEach {
66+
accumulator = operation(accumulator, it)
67+
}
68+
return accumulator
69+
}
5370
}
71+

0 commit comments

Comments
 (0)