views:

48

answers:

1

hello,

I'm trying to get a handle on the new Fiber class in Ruby 1.9 and I read that one of the more common applications for Fibers (and coroutines) is in state machines.

Unfortunately my Fiber-fu isn't up to much, so I was hoping one of you could show me a simple statemachine example in Ruby using Fibers

thanks :)

+1  A: 

http://github.com/rdp/ruby_tutorials_core/wiki/enumerator shows you how to wrap one that feeds another that feeds another.

To use this as a statemachine, I suppose it's splitting each "state" into its own fiber, like

AAAB (on input x) => AAAB (each [A,A,A,b] should be its own fiber, and just pass off input until it reaches the last)

rogerdpack