Last active
August 29, 2015 13:59
-
-
Save wingyplus/10748148 to your computer and use it in GitHub Desktop.
This file contains 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" | |
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