summaryrefslogtreecommitdiff
path: root/blinker/_async.py
diff options
context:
space:
mode:
Diffstat (limited to 'blinker/_async.py')
-rw-r--r--blinker/_async.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/blinker/_async.py b/blinker/_async.py
new file mode 100644
index 0000000..2b530e4
--- /dev/null
+++ b/blinker/_async.py
@@ -0,0 +1,28 @@
+import asyncio
+
+from blinker.base import Signal
+
+
+try:
+ schedule = asyncio.create_task
+except AttributeError:
+ schedule = asyncio.ensure_future
+
+
+@asyncio.coroutine
+def _wrap_plain_value(value):
+ """Pass through a coroutine *value* or wrap a plain value."""
+ if asyncio.iscoroutine(value):
+ value = yield from value
+ return value
+
+
+def send_async(self, *sender, **kwargs):
+ return [(receiver, schedule(_wrap_plain_value(value)))
+ for receiver, value
+ in self.send(*sender, **kwargs)]
+
+
+send_async.__doc__ = Signal.send_async.__doc__
+Signal.send_async = send_async
+