summaryrefslogtreecommitdiff
path: root/slixmpp/xmlstream/asyncio.py
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2015-02-28 13:34:52 +0100
committermathieui <mathieui@mathieui.net>2015-02-28 19:02:35 +0100
commitbf5d7c83af320b7af629857aab7060302abfabf5 (patch)
tree548e088aae38c780300b7f10fc7eec092db33a1a /slixmpp/xmlstream/asyncio.py
parentc66a4d4097a249efc029b761d6150378a54bf702 (diff)
downloadslixmpp-bf5d7c83af320b7af629857aab7060302abfabf5.tar.gz
slixmpp-bf5d7c83af320b7af629857aab7060302abfabf5.tar.bz2
slixmpp-bf5d7c83af320b7af629857aab7060302abfabf5.tar.xz
slixmpp-bf5d7c83af320b7af629857aab7060302abfabf5.zip
Change the API to make iq.send() always return a future
remove coroutine_wrapper, add a future_wrapper (which is only needed when the result stanza can be cached). Update the documentation as well.
Diffstat (limited to 'slixmpp/xmlstream/asyncio.py')
-rw-r--r--slixmpp/xmlstream/asyncio.py23
1 files changed, 9 insertions, 14 deletions
diff --git a/slixmpp/xmlstream/asyncio.py b/slixmpp/xmlstream/asyncio.py
index 76195237..0e0f610a 100644
--- a/slixmpp/xmlstream/asyncio.py
+++ b/slixmpp/xmlstream/asyncio.py
@@ -33,23 +33,18 @@ cls.idle_call = idle_call
real_run_once = cls._run_once
cls._run_once = my_run_once
-
-def coroutine_wrapper(func):
+def future_wrapper(func):
"""
- Make sure the result of a function call is a coroutine
- if the ``coroutine`` keyword argument is true.
+ Make sure the result of a function call is an asyncio.Future()
+ object.
"""
- def wrap_coro(result):
- if asyncio.iscoroutinefunction(result):
- return result
- else:
- return asyncio.coroutine(lambda: result)()
-
@wraps(func)
def wrapper(*args, **kwargs):
- if kwargs.get('coroutine', False):
- return wrap_coro(func(*args, **kwargs))
- else:
- return func(*args, **kwargs)
+ result = func(*args, **kwargs)
+ if isinstance(result, asyncio.Future):
+ return result
+ future = asyncio.Future()
+ future.set_result(result)
+ return future
return wrapper