Skip to content

Instantly share code, notes, and snippets.

@itang
Created August 11, 2013 13:51
Show Gist options
  • Save itang/6204989 to your computer and use it in GitHub Desktop.
Save itang/6204989 to your computer and use it in GitHub Desktop.
Rust VS Go - A very small taste of what it looks like
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()
}
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