Created
August 11, 2013 13:51
-
-
Save itang/6204989 to your computer and use it in GitHub Desktop.
Rust VS Go - A very small taste of what it looks like
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
package main | |
import ( | |
"fmt" | |
"sync" | |
) | |
func main() { | |
nums := []int{0, 1, 2, 3} | |
noms := []string{"Tim", "Eston", "Aaron", "Ben"} | |
var wg sync.WaitGroup | |
evens := make([]int, 0) | |
for _, v := range nums { | |
if v%2 == 0 { | |
evens = append(evens, v) | |
} | |
} | |
wg.Add(len(evens)) | |
for _, v := range evens { | |
go func(index int){ | |
msg := fmt.Sprintf("%s says hello from a lightwieght thread!", noms[index]) | |
fmt.Println(msg) | |
wg.Done() | |
}(v) | |
} | |
wg.Wait() | |
} |
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
fn main() { | |
let nums = [0, 1, 2, 3]; | |
let noms = ["Tim", "Eston", "Aaron", "Ben"]; | |
let mut evens = nums.iter().filter(|&x| x % 2 == 0); | |
for evens.advance |&num| { | |
do spawn { | |
let msg = fmt!("%s says hello from a lightweight thread!", | |
noms[num]); | |
println(msg); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment