[ 
https://issues.apache.org/jira/browse/THRIFT-148?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12634419#action_12634419
 ] 

Esteve Fernandez commented on THRIFT-148:
-----------------------------------------

I'm not sure if EventMachine is the exact Ruby equivalent of Twisted, but both 
implement the Reactor pattern and support 
[Futures|http://en.wikipedia.org/wiki/Future_(programming)] 
([Deferreds|http://twistedmatrix.com/documents/current/api/twisted.internet.defer.Deferred.html]
 in Twisted-speak, 
[Deferrables|http://rubyeventmachine.com/browser/trunk/docs/DEFERRABLES] in 
EventMachine)

Here's what I did in the client code:

1 - maintain a dictionary of Deferreds in your Client, keyed on seqid
2 - whenever a method needs to return a value, return a Deferred instead
3 - read incoming messages in the dataReceived method (client protocol)
4 - when the consumeFrame method encounters a complete message, call the 
appropiate recv_METHOD method in the client
5 - once the recv_METHOD method finishes, fire the Deferred

And this in the server code to support methods that return Deferreds:

1 - read incoming messages in the dataReceived method (server protocol)
2 - when the consumeFrame method encounters a complete message, call the 
Processor's process method
3 - wrap the self._handler.METHOD in a Deferred (with maybeDeferred)
4 - add a callback (and an errback if the method is supposed to throw an 
exception) to the previous Deferred

> Add support for Twisted
> -----------------------
>
>                 Key: THRIFT-148
>                 URL: https://issues.apache.org/jira/browse/THRIFT-148
>             Project: Thrift
>          Issue Type: Improvement
>          Components: Compiler (Python), Library (Python)
>            Reporter: Esteve Fernandez
>         Attachments: client.py, server.py, txthrift.patch
>
>
> This patch adds support for Twisted in both the compiler and the Python 
> library. Also attached are a client and a server based on the calculator 
> example.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to