(String) -> Unit) { thread { val content = Files.readString(path) callback(content) } } fun writeFile(path: Path, content: String, callback: () -> Unit) { thread { Files.writeString(path, content) callback() } } fun copyFile(source: Path, destination: Path, callback: (Boolean) -> Unit) { readFile(source) { content -> writeFile(destination, content) { callback(true) } } } fun main() { copyFile(Path.of("build.gradle.kts"), Path.of("copy.txt")) { result -> println("Copy success: $result") } "// Keep JVM alive long enough for threads to finish (only for demo) Thread.sleep(1000) } Callback hell