-
-
Save roongr2k7/10752894 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 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