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
class Yerba (val name: String, val brand: String, val db: Database){ | |
fun saveYerbaToDb(yerba: Yerba) { | |
db.save(yerba) | |
} | |
} |
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
override fun areItemsTheSame(oldItem: SleepNight, newItem: SleepNight): Boolean { | |
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | |
} | |
override fun areContentsTheSame(oldItem: SleepNight, newItem: SleepNight): Boolean { | |
TODO("not implemented") //To change body of created functions use File | Settings | File Templates. | |
} |
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
class SleepNightDiffCallback : DiffUtil.ItemCallback<SleepNight>() { | |
} |
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
fun main() { | |
println("Start") | |
val activity = Activity() | |
activity.doLotOfThings() | |
Thread.sleep(2000) | |
activity.destroy() | |
println("Done") | |
} | |
class Activity : CoroutineScope by CoroutineScope(Dispatchers.Default) { |
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
fun main() { | |
println("Start") | |
val activity = Activity() | |
activity.doLotOfThings() | |
Thread.sleep(2000) | |
activity.destroy() | |
println("Done") | |
} | |
private class Activity { |
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
fun main() = runBlocking { | |
log("Start") | |
hello() | |
log("Done") | |
} | |
private suspend fun hello() = coroutineScope { | |
launch { | |
// context of the parent, main runBlocking coroutine | |
println("[${Thread.currentThread().name}] from parent dispatcher") |
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
fun main() = runBlocking { | |
log("Start") | |
hello() // not suspendable, no waiting! | |
log("Done") | |
} | |
private fun CoroutineScope.hello() = launch(Dispatchers.Default) { | |
delay(1000L) | |
log("Hello1") |
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
fun main() = runBlocking { | |
println("Start") | |
hello() | |
println("Done") | |
} | |
suspend fun hello() = coroutineScope { | |
launch { | |
delay(1000L) | |
println("Hello") |
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
fun main() = runBlocking { | |
println("Start") | |
hello(this) | |
println("Done") | |
} | |
fun hello(scope: CoroutineScope) { // or as extension function | |
scope.launch { | |
delay(1000L) | |
println("Hello") |
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
fun main() = runBlocking { | |
println("Start") | |
// Start a coroutine (Child coroutine of runBlocking) | |
launch { // or `this.launch`. | |
delay(1000L) | |
println("Hello") | |
} | |
println("Done") | |
} |
NewerOlder