Skip to content

Instantly share code, notes, and snippets.

View tiwiz's full-sized avatar

Roberto Orgiu tiwiz

View GitHub Profile
suspend fun getDataAsync() =
async {
  getDataSync()
}
fun getDataSync() = weatherService.getData().execute().body()
interface NetworkService {
@GET(“whatever”)
  fun getData() : Call<OurType>
}
fab.onClickAsync { textView.countdown() }
fun View.onClickAsync(action: suspend () -> Unit) {
setOnClickListener {
  launch(UI) {
  action()
  }
  }
}
suspend fun TextView.countdown() {
for (i in 10 downTo 1) {
  text = "Countdown $i…"
  delay(1000)
  }
  text="Done!"
}
fun TextView.countdown() {
for (i in 10 downTo 1) {
  text = "Countdown $i…"
  delay(1000)
  }
  text="Done!"
}
val job = launch { … }
job.cancel()
launch(UI) {
for (i in 10 downTo 1) {
  hello.text = "Countdown $i…"
  delay(1000)
  }
  hello.text="Done!"
}
kotlin {
experimental {
  coroutines "enable"
  }
}