Hi,

I am trying to write a some code that expresses a series of  
Commands/Responses over a serial link.

In pseudocode, this is what I want to accomplish:

   conv = Conversation.new(connection) { |x|
       x.transmit(:init)
       x.wait_for(:ok)
       x.transmit(:get_user_input)
       x.wait_for(:user_data) { |message| response = message.text }
       puts response
     rescue TimeoutException => e
       x.retry if x.attempts < 3
   }
   conv.start

I suppose that something like that can be done with continuations and  
coroutines (which I have never used before)  Especially  
<http://www.all-thing.net/Ruby/coroutines.html> looks useful.

I would really appreciate any advice on how to best implement all this.   
Are there some projects/libraries that do something similar?

The interface I made up above could probably also be improved a lot and  
I'd appreciate your thoughts and suggestions.

Thank You,
Levin