dirk.dittert
12/23/2024, 5:30 PMinternal class ExampleWalker(val events : Channel<Path>) : SimpleFileVisitor<Path>() {
override fun visitFile(file: Path, attrs: BasicFileAttributes): FileVisitResult {
events.send(file)
return FileVisitResult.CONTINUE
}
}
fun main() = runBlocking {
val events = Channel<Path>()
Files.walkFileTree(Paths.get("/tmp"), ExampleWalker(events))
}
Obviously, it does not work like that because visitFile(...)
is not a suspend function. But I can't make it a suspend function because it is derived from SimpleFileVisitor
(which I can't change). What is the way to go?ephemient
12/23/2024, 6:12 PMephemient
12/23/2024, 6:13 PMdirk.dittert
12/23/2024, 7:16 PMkevin.cianfarini
12/23/2024, 7:26 PMtrySend
every element.dirk.dittert
12/23/2024, 7:32 PMdirectory.walk(PathWalkOption.INCLUDE_DIRECTORIES, PathWalkOption.BREADTH_FIRST).forEach { path ->
println(path)
}
Results in
#
# A fatal error has been detected by the Java Runtime Environment:
#
# SIGSEGV (0xb) at pc=0x0000000105a6111c, pid=78801, tid=33539
#
# JRE version: OpenJDK Runtime Environment Homebrew (11.0.25) (build 11.0.25+0)
# Java VM: OpenJDK 64-Bit Server VM Homebrew (11.0.25+0, mixed mode, tiered, compressed oops, g1 gc, bsd-aarch64)
# Problematic frame:
# V [libjvm.dylib+0x69511c] ObjectSynchronizer::inflate(Thread*, oopDesc*, ObjectSynchronizer::InflateCause)+0x18c
#