Upgrade to Pro — share decks privately, control downloads, hide ads and more …

EAsync Kotlin

Roberto Orgiu
November 17, 2017

EAsync Kotlin

Slides about Kotlin Coroutines - Talk kept at DevFest Catania and DevFest Istanbul

Roberto Orgiu

November 17, 2017
Tweet

More Decks by Roberto Orgiu

Other Decks in Technology

Transcript

  1. Roberto Orgiu @_tiwiz launch(UI){T for (i in 10 downTo 1)

    { hello.text = "Countdown $i ..." delay(500) }T hello.text="Done!" }T
  2. Roberto Orgiu @_tiwiz launch( UI){T for (i in 10 downTo

    1) { hello.text = "Countdown $i ..." delay(500) }T hello.text="Done!" }T
  3. Roberto Orgiu @_tiwiz launch(UI){T for (i in 10 downTo 1)

    { hello.text = "Countdown $i ..." delay(500) }T hello.text="Done!" }T
  4. Roberto Orgiu @_tiwiz launch(UI){T for (i in 10 downTo 1)

    { hello.text = "Countdown $i ..." delay(500) }T hello.text="Done!" }T val job = job.cancel()
  5. Roberto Orgiu @_tiwiz suspend fun TextView.countdown()_{_ for_(i_in 10 downTo 1)_{_

    text = "Countdown $i ..." delay(1000) }_ text="Done!" }_
  6. Roberto Orgiu @_tiwiz suspend fun TextView.countdown()_{_}_ fun View.onClick(action: suspend ()_

    ->_Unit)_{_ setOnClickListener { launch(UI) { action() } } }_
  7. Roberto Orgiu @_tiwiz fun View.onClick(action: suspend () -> Deferred<Response>) {

    setOnClickListener { launch(UI) { toggleWaitingView() val response = action().await() bindUiTo(response) toggleContentView() }T }T }T
  8. Roberto Orgiu @_tiwiz fun View.onClick(action: suspend () -> Deferred<Response>) {

    setOnClickListener { launch(UI) { toggleWaitingView() val response = action().await() bindUiTo(response) toggleContentView() }T }T }T
  9. Roberto Orgiu @_tiwiz fun View.onClick(action: suspend () -> Deferred<Response>) {

    setOnClickListener { launch(UI) { toggleWaitingView() val response = action().await() bindUiTo(response) toggleContentView() }T }T }T
  10. Roberto Orgiu @_tiwiz @Test fun coroutine_test() {T val actualWeather =

    runBlocking {T getWeatherAsync().await() }T …T }T
  11. Roberto Orgiu @_tiwiz @Test fun coroutine_test() {T val actualWeather =

    runBlocking {T getWeatherAsync().await() }T …T }T