Skip to content

Instantly share code, notes, and snippets.

@ekoo
Created May 5, 2020 23:12
Show Gist options
  • Save ekoo/a1ea2ba169e325a4443eaeaa6f56573e to your computer and use it in GitHub Desktop.
Save ekoo/a1ea2ba169e325a4443eaeaa6f56573e to your computer and use it in GitHub Desktop.
fun jagaKonter() = viewModelScope.launch {
val listrik = async { beliListrik() }
val pulsa = async { beliPulsa() }
Log.d("example", "Semua Transaksi Selesai, Total Pendapatan : Rp. ${listrik.await()+pulsa.await()}")
}
suspend fun beliListrik(): Int{
Log.d("example", "Melayani Pelanggan Pertama")
delay(7000L)
val price = 52000
Log.d("example", "Transaksi Pertama Selesai")
return price
}
suspend fun beliPulsa(): Int{
Log.d("example", "Melayani Pelanggan Kedua")
delay(5000L)
val price = 21000
Log.d("example", "Transaksi Kedua Selesai")
return price
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment