Skip to content

Instantly share code, notes, and snippets.

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