Skip to content

Instantly share code, notes, and snippets.

@hogedigo
Created February 21, 2014 00:54
Show Gist options
  • Save hogedigo/9126727 to your computer and use it in GitHub Desktop.
Save hogedigo/9126727 to your computer and use it in GitHub Desktop.
future sample
package main
import "fmt"
type task struct {
url string
result chan string
}
func main() {
tasks := [...]*task{
&task{"http://hoge.example.com/", make(chan string)},
&task{"http://moke.example.com/", make(chan string)},
&task{"http://bosukete.example.com/", make(chan string)},
}
for _, t := range tasks {
go func(t *task) {
t.result<-t.url + "result"
}(t)
}
for _, t := range tasks {
fmt.Println(<-t.result)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment