Skip to content

Commit

Permalink
TwistedChannel correctly handles multi-argument deferreds.
Browse files Browse the repository at this point in the history
Twisted deferreds expect a single argument, and the docstring
of TwistedChannel says it will call them with a tuple
in case the original callback receives more than one.

This commit makes the comment true.
  • Loading branch information
eivanov committed Jul 5, 2013
1 parent 4624ab9 commit 53cce88
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pika/adapters/twisted_connection.py
Expand Up @@ -147,7 +147,19 @@ def wrapped(*args, **kwargs):
d = defer.Deferred()
self.__calls.add(d)
d.addCallback(self.__clear_call, d)
kwargs['callback'] = d.callback

def single_argument(*args):
"""
Make sure that the deferred is called with a single argument.
In case the original callback fires with more than one, convert
to a tuple.
"""
if len(args) > 1:
d.callback(tuple(args))
else:
d.callback(*args)

kwargs['callback'] = single_argument

try:
method(*args, **kwargs)
Expand Down

0 comments on commit 53cce88

Please sign in to comment.