Created
September 16, 2019 06:00
-
-
Save CanerPatir/3731f1f0791c2982836c5d958a4d996c 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 | |
| println("[${(SimpleDateFormat("hh:mm:ss")).format(Date())}] operation1 finished") | |
| return 50 | |
| } | |
| suspend fun operation2(): Int { | |
| delay(1000L) | |
| println("[${(SimpleDateFormat("hh:mm:ss")).format(Date())}] operation2 finished") | |
| return 60 | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment