This file contains 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
suspend fun fetchTwoDocs() = coroutineScope { | |
val deferreds = listOf( | |
async { fetchDoc(1) }, | |
async { fetchDoc(2) } | |
) | |
deferreds.awaitAll() | |
} |
This file contains 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 { | |
val handler = CoroutineExceptionHandler { _, exception -> | |
println("CoroutineExceptionHandler hot $exception") | |
} | |
val job = launch(handler) { | |
supervisorScope { | |
launch { | |
downloadImage() | |
println("finish download 1") | |
} |
This file contains 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 { | |
val job = launch { | |
updateUi()... | |
coroutineScope { | |
launch { | |
downloadImage() | |
} | |
launch { | |
downloadSounds() |
This file contains 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 { | |
val job = launch { | |
launch { | |
downloadImage() | |
} | |
launch { | |
downloadSounds() | |
} | |
println("finish downloads") |
This file contains 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 { | |
val job1 = launch { | |
delay(2000) | |
downloadData() | |
print("Completed Job 1") | |
} | |
val job2 = launch { | |
delay(2000) | |
syncUserDetails() |
This file contains 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 { | |
val job = launch { | |
delay(2000) | |
updateDataBase() | |
print("Completed Job") | |
} | |
job.join() | |
println("Finish") | |
readDataBase() | |
} |
This file contains 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 { | |
val job = launch { | |
delay(2000) | |
print("Completed Job") | |
} | |
println("Finish") | |
} |
This file contains 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 ExampleActivity : ComponentActivity(R.layout.activity_example) { | |
override fun onCreate(savedInstanceState: Bundle?) { | |
super.onCreate(savedInstanceState) | |
// Add menu items without overriding methods in the Activity | |
addMenuProvider(object : MenuProvider { | |
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) { | |
// Add menu items here | |
menuInflater.inflate(R.menu.example_menu, menu) |
NewerOlder