Skip to content

Instantly share code, notes, and snippets.

@roongr2k7
Forked from wingyplus/event.go
Last active August 29, 2015 13:59
Show Gist options
  • Save roongr2k7/10752894 to your computer and use it in GitHub Desktop.
Save roongr2k7/10752894 to your computer and use it in GitHub Desktop.
package main
import "fmt"
type Signal string
func eventLoop(addEvent chan Signal, echoEvent chan Signal, quit chan bool) {
for {
select {
case obj := <-addEvent:
fmt.Printf("add %v", obj)
case msg := <-echoEvent:
fmt.Printf("echo %s", msg)
case <-quit:
return
}
}
}
func main() {
add, echo, quit := make(chan Signal), make(chan Signal), make(chan bool)
go eventLoop(add, echo, quit)
var message string
var command int
for {
fmt.Scanf("%d", &command)
switch command {
case 1:
fmt.Scanf("%s", &message)
add <- Signal(message)
case 2:
fmt.Scanf("%s", &message)
echo <- Signal(message)
case 3:
quit <- true
return
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment