Last active
May 1, 2021 08:45
-
-
Save d-plaindoux/9005171dccd1ffa83594cb13ed5380b0 to your computer and use it in GitHub Desktop.
Naive example composing functions using the network, http web client and files.
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 doSomething(webView: WebView): Int { | |
val v1 = firstAction() | |
val v2 = secondAction(webView) | |
val v3 = thirdAction() | |
return v1 + v2 + v3 // .i.e. 42 | |
} | |
suspend fun firstAction(): Int = | |
// Do some stuff on the network for example ... | |
10 | |
suspend fun secondAction(webView: WebView): Int = | |
suspendCoroutine { cont -> | |
webView.webViewClient = object : WebViewClient() { | |
override fun onPageFinished(view: WebView?, url: String?) { | |
cont.resume(30) | |
} | |
} | |
webView.loadUrl(AnURL) | |
} | |
suspend fun thirdAction(): Int = | |
// Do some stuff using file for instance ... | |
2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This last version uses Kotlin idiomatic suspended coroutines (No more Arrow.Kt)