Last active
October 31, 2019 00:52
-
-
Save pencelab/106be556362cae556864a6632527211f to your computer and use it in GitHub Desktop.
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 sumIsEvenAsync() = async { | |
val sum = sumThreeRandomNumbers(OPERATION_IS_EVEN) | |
log("$OPERATION_IS_EVEN: Sum = $sum") | |
sum % 2 == 0 | |
} | |
fun sumAverageAsync() = async { | |
val sum = sumThreeRandomNumbers(OPERATION_AVERAGE) | |
log("$OPERATION_AVERAGE: Sum = $sum") | |
sum.toFloat() / 3 | |
} | |
fun sumSquareAsync() = async { | |
val sum = sumThreeRandomNumbers(OPERATION_SQUARE) | |
log("$OPERATION_SQUARE: Sum = $sum") | |
sum * sum | |
} | |
private suspend fun sumThreeRandomNumbers(operation: String): Int { | |
val r1 = async { myRandomNumberSuccess(operation) } | |
val r2 = async { myRandomNumberSuccess(operation) } | |
val r3 = async { myRandomNumberSuccess(operation) } | |
return r1.await() + r2.await() + r3.await() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment