summaryrefslogtreecommitdiff
path: root/blinker/_async.py
diff options
context:
space:
mode:
Diffstat (limited to 'blinker/_async.py')
-rw-r--r--blinker/_async.py24
1 files changed, 24 insertions, 0 deletions
diff --git a/blinker/_async.py b/blinker/_async.py
new file mode 100644
index 0000000..3bf87d3
--- /dev/null
+++ b/blinker/_async.py
@@ -0,0 +1,24 @@
+import asyncio
+
+from blinker.base import Signal
+
+
+try:
+ schedule = asyncio.ensure_future
+except AttributeError:
+ schedule = asyncio.async
+
+
+@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(scheduler=schedule):
+ def adapter(receiver, sender, kwargs):
+ result = receiver(sender, **kwargs)
+ return scheduler(_wrap_plain_value(result))
+ return adapter