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 loadItems() { | |
showLoadingView() | |
val data = requestData() | |
hideLoadingView() | |
appendItemsToListView(data) | |
} |
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 loadItems() { | |
withContext(Dispatchers.Main) { | |
showLoadingView() | |
} | |
withContext(Dispatchers.IO) { | |
val data = requestData() | |
} | |
withContext(Dispatchers.Main) { | |
hideLoadingView() | |
appendItemsToListView(data) |
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 loadItems() = withContext(Dispatchers.IO) { | |
withContext(Dispatchers.Main) { | |
showLoadingView() | |
} | |
val data = requestData() | |
withContext(Dispatchers.Main) { | |
hideLoadingView() | |
appendItemsToListView(data) | |
} | |
} |
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 loadItems() = withContext(Dispatchers.Main) { | |
showLoadingView() | |
val data = withContext(Dispatchers.IO) { | |
requestData() | |
} | |
hideLoadingView() | |
appendItemsToListView(data) | |
} |
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 loadItems() { | |
showLoadingView() | |
val data = withContext(Dispatchers.IO) { | |
requestData() | |
} | |
hideLoadingView() | |
appendItemsToListView(data) | |
} |
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() { | |
log("Start") | |
val myObject = MyObject() | |
runBlocking { | |
log("RunBlocking start") | |
val def = myObject.sumRandomNumbersAsync() |
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() { | |
log("Start") | |
val operator = Operator() | |
runBlocking { | |
//To be implemented... | |
} | |
operator.release() |
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
private suspend fun myRandomNumber(): Int = withContext(Dispatchers.Default) { | |
log("Retrieving random number...") | |
delay(2000) //Simulating a heavy computation | |
val random = (1..100).random() | |
log("Random Number = $random") | |
random | |
} |
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
runBlocking { | |
val defIsEven = operator.sumIsEvenAsync() | |
val defAverage = operator.sumAverageAsync() | |
launch { | |
try { | |
log("Operation [Is Even] Result = ${defIsEven.await()}") | |
} catch (e: Exception) { | |
log("Operation [Is Even] Caught: [ $e ]") | |
} finally { |
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
private suspend fun myRandomNumberSuccess(operation: String): Int = withContext(Dispatchers.Default) { | |
log("$operation Retrieving random number...") | |
delay(2000) //Simulating a heavy computation | |
val random = (1..100).random() | |
log("$operation Random Number = $random") | |
random | |
} | |
private suspend fun myRandomNumberFail(operation: String): Int = withContext(Dispatchers.Default) { | |
log("$operation Retrieving random number...") |
OlderNewer