Created
August 31, 2015 02:32
-
-
Save hirokazumiyaji/c6bbf27f246b86cee6de to your computer and use it in GitHub Desktop.
worker
This file contains hidden or 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" | |
"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