Last active
March 1, 2017 13:24
-
-
Save gzoritchak/2b8ee80d64c062dc728021b1831d00b5 to your computer and use it in GitHub Desktop.
This file contains 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
// runs the code in the background thread pool | |
fun asyncOverlay() = async(CommonPool) { | |
// start two async operations | |
val original = asyncLoadImage("original") | |
val overlay = asyncLoadImage("overlay") | |
// and then apply overlay to both results | |
applyOverlay(original.await(), overlay.await()) | |
} | |
// launches new coroutine in UI context | |
launch(UI) { | |
// wait for async overlay to complete | |
val image = asyncOverlay().await() | |
// and then show it in UI | |
showImage(image) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment