by chubot · 13y ago · 0 comments
http://eli.thegreenplace.net/2009/08/29/co-routines-as-an-al...
Basically use stack state and goroutines to avoid explicit states. Unlike Python, Go might take multiple threads to do this?
For an simple example--written in many languages including Python and Go--with two stateful coroutines, you can check this out: http://rosettacode.org/wiki/Synchronous_concurrency
That is, Go doesn't provide synchronous dataflow. Thanks for the link, I will be looking at that!
edit: or maybe it does with a channel size of 1? The Rob Pike lexer talk mentioned a few times here was doing some trick with that.
And you're on the right track regarding how channels work. They can be synchronous if you like. Effectively, such channels have no buffering. Also, you don't need to use OS threading at all to solve such problems in Go. It's possible to run code with lots of cooperating goroutines in a single OS thread.
Edit: By the way, I'm not familiar with Python so I'm just guessing at how the send method and the yield form work.
Edit 3: Notice that I forgot to close the "frames" channel. So if this were a long-running program, that goroutine running frameReceiver would be a leaked resource.