Skip to content

Instantly share code, notes, and snippets.

@juliuscanute
Created November 30, 2019 21:07
Show Gist options
  • Select an option

  • Save juliuscanute/b97510bb74aba0796e011c283016ec76 to your computer and use it in GitHub Desktop.

Select an option

Save juliuscanute/b97510bb74aba0796e011c283016ec76 to your computer and use it in GitHub Desktop.
[Change code to suspendable] #kotlin #coroutine
suspend fun readFileSuspend(path: String): File =
suspendCoroutine {
readFile(path) { file ->
it.resume(file)
}
}
fun readFile(path: String, onReady: (File) -> Unit) {
Thread.sleep(1000)
// some heavy operation
onReady(File(path))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment