summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorOmer Katz <omer.drow@gmail.com>2019-03-19 11:58:18 +0200
committerOmer Katz <omer.drow@gmail.com>2019-03-19 11:58:18 +0200
commit2cedaa3e129a9c7afa4584dad980debd118c95f5 (patch)
treebf60a7dbac53941d5a04cccb6cffee5a07643cbf
parent64f60e6a04cdd01c8fe0b7b998eca8cbf8c3a140 (diff)
downloadpy-amqp-write-then-callback.tar.gz
Ensure callback is called only when we're done writing to the socket.write-then-callback
-rw-r--r--amqp/abstract_channel.py17
-rw-r--r--requirements/default.txt2
-rw-r--r--t/unit/test_abstract_channel.py6
3 files changed, 14 insertions, 11 deletions
diff --git a/amqp/abstract_channel.py b/amqp/abstract_channel.py
index 8530bec..73d91d9 100644
--- a/amqp/abstract_channel.py
+++ b/amqp/abstract_channel.py
@@ -42,19 +42,20 @@ class AbstractChannel(object):
def send_method(self, sig,
format=None, args=None, content=None,
wait=None, callback=None, returns_tuple=False):
- p = promise()
conn = self.connection
if conn is None:
raise RecoverableConnectionError('connection already closed')
args = dumps(format, args) if format else bytes_if_py2('')
- try:
- conn.frame_writer(1, self.channel_id, sig, args, content)
- except StopIteration:
- raise RecoverableConnectionError('connection already closed')
- # TODO temp: callback should be after write_method ... ;)
- if callback:
- p.then(callback)
+ def _write_method():
+ try:
+ conn.frame_writer(1, self.channel_id, sig, args, content)
+ except StopIteration:
+ raise RecoverableConnectionError('connection already closed')
+
+ p = promise(fun=_write_method,
+ callback=callback,
+ ignore_result=True)
p()
if wait:
return self.wait(wait, returns_tuple=returns_tuple)
diff --git a/requirements/default.txt b/requirements/default.txt
index e7d1b74..4edfe48 100644
--- a/requirements/default.txt
+++ b/requirements/default.txt
@@ -1 +1 @@
-vine>=1.1.3
+vine>=1.3.0
diff --git a/t/unit/test_abstract_channel.py b/t/unit/test_abstract_channel.py
index 01acf08..a4f3081 100644
--- a/t/unit/test_abstract_channel.py
+++ b/t/unit/test_abstract_channel.py
@@ -6,7 +6,7 @@ from vine import promise
from amqp.abstract_channel import AbstractChannel
from amqp.exceptions import AMQPNotImplementedError, RecoverableConnectionError
from amqp.serialization import dumps
-from case import Mock, patch
+from case import Mock, patch, ANY
class test_AbstractChannel:
@@ -48,7 +48,9 @@ class test_AbstractChannel:
def test_send_method__wait(self):
self.c.wait = Mock(name='wait')
self.c.send_method((50, 60), 'iB', (30, 0), wait=(50, 61))
- self.c.wait.assert_called_with((50, 61), returns_tuple=False)
+ self.c.wait.assert_called_with((50, 61),
+ callback=ANY,
+ returns_tuple=False)
def test_send_method__no_connection(self):
self.c.connection = None