Very simple test program to try to understand coroutines and flows and buffereing.
Maint.kt:
package org.gvs.testflows
import kotlinx.coroutines.*
import kotlinx.coroutines.flow.*
import kotlinx.coroutines.flow.buffer
fun simple(): Flow<Int> = flow {
for (i in 1..3) {
delay(100)
emit(i)
}
}
fun main() = runBlocking<Unit> {
simple()
.buffer(10)
.collect { value ->
delay(300)
println(value)
}
}
Works fine if I take out “.buffer(10)”. when I have the buffer in the flow I get:
"C:\Program Files\Microsoft\jdk-17.0.8.7-hotspot\bin\java.exe" "-javaagent:E:\Program Files\JetBrains\IntelliJ IDEA 2024.1\lib\idea_rt.jar=51709:E:\Program Files\JetBrains\IntelliJ IDEA 2024.1\bin" -Dfile.encoding=UTF-8 -classpath E:\ideaprojects\untitled2\build\classes\kotlin\main;C:\Users\Shawn\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-android\1.3.9\df17db5e329363c4e9cc7bf5b661ce3723a3e460\kotlinx-coroutines-android-1.3.9.jar;C:\Users\Shawn\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlin\kotlin-stdlib\1.9.23\dbaadea1f5e68f790d242a91a38355a83ec38747\kotlin-stdlib-1.9.23.jar;C:\Users\Shawn\.gradle\caches\modules-2\files-2.1\org.jetbrains\annotations\13.0\919f0dfe192fb4e063e7dacadee7f8bb9a2672a9\annotations-13.0.jar;C:\Users\Shawn\.gradle\caches\modules-2\files-2.1\org.jetbrains.kotlinx\kotlinx-coroutines-core-jvm\1.3.9\4be434f5e86c1998a273e7f19a7286440894f0b0\kotlinx-coroutines-core-jvm-1.3.9.jar org.gvs.testflows.MainKt
Exception in thread "main" java.lang.NoSuchMethodError: 'kotlinx.coroutines.flow.Flow kotlinx.coroutines.flow.FlowKt.buffer$default(kotlinx.coroutines.flow.Flow, int, kotlinx.coroutines.channels.BufferOverflow, int, java.lang.Object)'
at org.gvs.testflows.MainKt$main$1.invokeSuspend(Main.kt:20)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:56)
at kotlinx.coroutines.EventLoopImplBase.processNextEvent(EventLoop.common.kt:274)
at kotlinx.coroutines.BlockingCoroutine.joinBlocking(Builders.kt:84)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking(Builders.kt:59)
at kotlinx.coroutines.BuildersKt.runBlocking(Unknown Source)
at kotlinx.coroutines.BuildersKt__BuildersKt.runBlocking$default(Builders.kt:38)
at kotlinx.coroutines.BuildersKt.runBlocking$default(Unknown Source)
at org.gvs.testflows.MainKt.main(Main.kt:18)
at org.gvs.testflows.MainKt.main(Main.kt)
Process finished with exit code 1
Thoughts?