Skip to content

Instantly share code, notes, and snippets.

@hirokazumiyaji
Created August 31, 2015 02:32
Show Gist options
  • Save hirokazumiyaji/c6bbf27f246b86cee6de to your computer and use it in GitHub Desktop.
Save hirokazumiyaji/c6bbf27f246b86cee6de to your computer and use it in GitHub Desktop.
worker
package main
import (
"fmt"
"os"
"os/signal"
"syscall"
)
func main() {
signals := make(chan os.Signal, 10)
signal.Notify(signals, syscall.SIGTERM)
quit := make(chan bool)
messages := make(chan string)
go func() {
loop:
for {
select {
case sig := <-signals:
fmt.Println("signal: ", sig)
signal.Stop(signals)
quit <- true
break loop
case msg := <-messages:
fmt.Println("message: ", msg)
}
}
}()
for i := 1; i < 11; i++ {
messages <- fmt.Sprintf("No.%d", i)
}
<-quit
fmt.Println("Finish")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment