Created
September 16, 2019 06:00
-
-
Save CanerPatir/8dc842fd5e1e9a3a006463952a178900 to your computer and use it in GitHub Desktop.
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 { | |
| val deferred1 = async { operation1() } | |
| val deferred2 = async { operation2() } | |
| println("[${(SimpleDateFormat("hh:mm:ss")).format(Date())}] Awaiting computations...") | |
| val result = deferred1.await() + deferred2.await() | |
| println("[${(SimpleDateFormat("hh:mm:ss")).format(Date())}] The result is $result") | |
| } | |
| } | |
| suspend fun operation1(): Int { | |
| delay(2000L) // simulated computation | |
| printCurrentTime("operation1 finished") | |
| return 131 | |
| } | |
| suspend fun operation2(): Int { | |
| delay(1000L) | |
| printCurrentTime("operation2 finished") | |
| return 9 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment