diff options
| author | jason kirtland <jek@discorporate.us> | 2016-08-22 14:53:57 -0700 |
|---|---|---|
| committer | jason kirtland <jek@discorporate.us> | 2016-08-22 14:53:57 -0700 |
| commit | f4c1037f3c361b5fa904d3acec7c74f4172c9b30 (patch) | |
| tree | eee7774c9b5aecb45ab4ddca1ba9da688016d206 /blinker/_async.py | |
| parent | 7303d4bf1ab8a339a194d0d1935770bef43c3cca (diff) | |
| download | blinker-feature/receiver-adapter.tar.gz | |
Exploratory commit for feedback, adds an async adapter, "send_robust" adapter, and positional call signature adapter.feature/receiver-adapter
Diffstat (limited to 'blinker/_async.py')
| -rw-r--r-- | blinker/_async.py | 24 |
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 |
