SHARE
TWEET

Untitled

a guest Oct 21st, 2019 47 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. fun main() {
  2.  
  3.     Database().load("https://jsonplaceholder.typicode.com/users/1", object : Callback {
  4.         override fun onLoadData(result: String) {
  5.             Thread.sleep(2000) // imitation of long query
  6.             println(result)
  7.         }
  8.     })
  9. }
  10.  
  11.  
  12. /*
  13. *   Callback using via HighOrderFunctions / Unit
  14. *   https://metanit.com/kotlin/tutorial/3.7.php
  15. * */
  16.  
  17. class DatabaseUnit {
  18.     fun load(link: String, callback: (Any) -> Unit) {
  19.         val result = RequestHelper.getData(link)
  20.         callback(result)
  21.     }
  22. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top