Created
October 20, 2012 13:26
-
-
Save pote/3923272 to your computer and use it in GitHub Desktop.
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
go func() { | |
for i := 1; i < 100; i++ { | |
fmt.Println(i) | |
} | |
}() | |
go SomeMotherfuckingExpensiveLoop() | |
go AnotherMotherfuckingLoop() | |
// app is keep going here... | |
var killed channel bool | |
killed := make(channel bool) | |
go func() { | |
<-killed | |
} | |
killed <- true | |
<-time.After(10 * time.Second) |
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
type Jules struct {} | |
func (jules *Jules) IsStoned() bool { | |
return false | |
} | |
type Vince struct {} | |
func (vince *Vince) IsStoned() bool { | |
return true | |
} | |
type Stoner interface { | |
IsStoned() bool | |
} | |
func PrintStoner(s Stoner) { | |
fmt.Printf("%x", s) | |
} | |
var x interface{} |
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
func main() { | |
for i := 0; i < 10; i++ { | |
fmt.Println(i) | |
} | |
} |
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
func main() { | |
go func() { | |
for i := 0; i < 10; i++ { | |
fmt.Println(i) | |
} | |
}() | |
} |
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
func PrintShit() { | |
for i := 0; i < 10; i++ { | |
fmt.Println(i) | |
} | |
} | |
func main() { | |
go PrintShit() | |
<-time.After(2 * time.Second) | |
} |
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
func PrintShit(done chan bool) { | |
for i := 1; i < 10; i++ { | |
fmt.Println(i) | |
} | |
done <- true | |
} | |
func main() { | |
isItThereYet := make(chan bool) | |
go PrintShit(isItThereYet) | |
<-isItThereYet | |
} |
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
func PrintShit() <-chan bool { | |
done := make(chan bool) | |
go func() { | |
for i := 1; i < 10; i++ { | |
fmt.Println(i) | |
} | |
done <- true | |
} | |
return done | |
} | |
func main() { | |
<-PrintShit() | |
} |
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
type Vince struct { | |
isStoned bool | |
} | |
func (vince *Vince) IsStoned() bool { | |
return vince.isStoned | |
} | |
func (vince *Vince) SmokePot() bool { | |
vince.isStoned = true | |
} | |
type FuckingInt int | |
func (x FuckingInt) Square() int { | |
return int(x) * int(x) | |
} |
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
select { | |
case <-jules.Shoot(): | |
fmt.Println("Jules killed motherfucker") | |
case <-vince.Shoot(): | |
fmt.Println("Vince killed motherfucker") | |
} | |
select { | |
// *snip* | |
default: | |
// do something while waiting for the channels. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment