Created
November 30, 2019 21:07
-
-
Save juliuscanute/b97510bb74aba0796e011c283016ec76 to your computer and use it in GitHub Desktop.
[Change code to suspendable] #kotlin #coroutine
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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