Created
February 21, 2014 00:54
-
-
Save hogedigo/9126727 to your computer and use it in GitHub Desktop.
future sample
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" | |
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