Last active
August 29, 2015 13:55
-
-
Save zeekay/8705007 to your computer and use it in GitHub Desktop.
Python vs Go round 2.
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" | |
func ping(c chan string) { | |
fmt.Println("starting ping") | |
for { | |
c <- "ping" | |
pong := <-c | |
fmt.Println(pong) | |
} | |
} | |
func pong(c chan string) { | |
fmt.Println("starting pong") | |
for { | |
ping := <-c | |
fmt.Println(ping) | |
c <- "pong" | |
} | |
} | |
func main() { | |
c := make(chan string) | |
go ping(c) | |
go pong(c) | |
// Block forever | |
select {} | |
} |
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
def ping(): | |
while True: | |
yield "ping" | |
pong = yield | |
print pong | |
def pong(): | |
while True: | |
ping = yield | |
print ping | |
yield "pong" | |
# ok but how to route them around? no channels :( |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the second : dispatcher is a good idea. http://pydispatcher.sourceforge.net/