Skip to content

Instantly share code, notes, and snippets.

@furu
Created September 8, 2014 11:35
Show Gist options
  • Save furu/b6ee07adabeb2bac821f to your computer and use it in GitHub Desktop.
Save furu/b6ee07adabeb2bac821f to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"math/rand"
"os"
"os/signal"
"sync"
"syscall"
"time"
)
func main() {
for {
fmt.Println("(main) ^o^ < ショキカー")
wg := new(sync.WaitGroup)
cy := run(wg)
cx := make(chan os.Signal, 1)
signal.Notify(cx, syscall.SIGURG, syscall.SIGPIPE)
fmt.Println("(main) ^o^ < channel マッテルー")
select {
case sig := <-cx:
fmt.Println("(main) ^o^ <", sig)
cy <- true
break
case <-cy:
fmt.Println("(main) ^o^ < オワルー")
break
}
wg.Wait()
}
}
func run(wg *sync.WaitGroup) chan bool {
fmt.Println("(run) ^o^ < run() ナウ!")
defer fmt.Println("(run) ^o^ < run() ヌケター")
c := make(chan bool)
wg.Add(1)
go func() {
rand.Seed(time.Now().Unix())
for {
select {
case <-c:
fmt.Println("(nameless func) ^o^ < オワルー")
goto End
default:
n := rand.Intn(10)
fmt.Println("(nameless func) ^o^ < ", n)
if n == 0 {
fmt.Println("(nameless func) ^o^ < ナンカシッパイシター")
c <- true
goto End
} else {
fmt.Println("(nameless func) ^o^ < ナンカショリシテルー")
time.Sleep(10 * time.Second)
}
}
}
End:
wg.Done()
}()
return c
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment