Skip to content

Instantly share code, notes, and snippets.

@wozozo
Created March 5, 2015 12:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wozozo/d428b178a4c5e4ce65cc to your computer and use it in GitHub Desktop.
Save wozozo/d428b178a4c5e4ce65cc to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"time"
)
func main() {
๐Ÿƒ := make(chan int)
๐Ÿ’จ := make(chan int)
๐Ÿ˜ƒ := make(chan int)
go ๅ€‹ๅฎคใฎไธญใซใ„ใ‚‹่‡ชๅˆ†(๐Ÿƒ, ๐Ÿ’จ, ๐Ÿ˜ƒ)
๐Ÿ’จ <- 0
time.Sleep(3 * time.Second)
๐Ÿƒ <- 0
๐Ÿ˜ƒ <- 0
}
func ๅ€‹ๅฎคใฎไธญใซใ„ใ‚‹่‡ชๅˆ†(๐Ÿƒ, ๐Ÿ’จ, ๐Ÿ˜ƒ chan int) {
for {
select {
case <-๐Ÿƒ:
go ๐Ÿšฝ()
case <-๐Ÿ’จ:
go ๐Ÿ’ฉ()
case <-๐Ÿ˜ƒ:
time.Sleep(30 * time.Second)
fmt.Println("๐Ÿ˜ƒ")
return
}
}
}
func ๐Ÿšฝ() {
fmt.Println("๐Ÿšฝใ€œ")
time.Sleep(10*time.Second)
}
func ๐Ÿ’ฉ() {
fmt.Println("๐Ÿ’ฉใ€œ")
time.Sleep(3*time.Minute)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment