Skip to content

Instantly share code, notes, and snippets.

@davidkellis
Last active September 15, 2017 16:14
Show Gist options
  • Save davidkellis/88361b28e7d96bc8905fd01fee5ec101 to your computer and use it in GitHub Desktop.
Save davidkellis/88361b28e7d96bc8905fd01fee5ec101 to your computer and use it in GitHub Desktop.
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