Last active
September 15, 2017 16:14
-
-
Save davidkellis/88361b28e7d96bc8905fd01fee5ec101 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
fn slowAdd(x: Int, y: Int) -> Int { | |
sleep(2.seconds) | |
x + y | |
} | |
// main1 takes 4 seconds to run | |
fn main1() { | |
a = slowAdd(1, 2) | |
b = slowAdd(10, 20) | |
puts(a + b) | |
} | |
// main2 takes 2 seconds to run | |
fn main2() { | |
a = async slowAdd(1, 2) | |
b = async slowAdd(10, 20) | |
puts(a + b) | |
} | |
asyncfn slowAdd(x: Int, y: Int) -> Int { | |
sleep(2.seconds) | |
x + y | |
} | |
// main3 takes 2 seconds to run | |
fn main3() { | |
a = slowAdd(1, 2) | |
b = slowAdd(10, 20) | |
puts(a + b) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment