Skip to content

Instantly share code, notes, and snippets.

@SabagRonen
Last active January 13, 2018 20:20
Show Gist options
  • Save SabagRonen/8ab1d99452e8d6e865426e21d7362198 to your computer and use it in GitHub Desktop.
Save SabagRonen/8ab1d99452e8d6e865426e21d7362198 to your computer and use it in GitHub Desktop.
Clean Architecture and Kotlin Coroutines post loading image async
suspend fun fetchImage(key: String, storage: Storage, imageFetcher: ImageFetcher) : Bitmap {
val url = async {storage.getUrlForKey(key)}.await()
val image = async { imageFetcher.getImageFromUrl(url) }
println("this might be run after the async have started")
return image.await()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment