From d841e82241a209573a1da638aa64921c7e65b811 Mon Sep 17 00:00:00 2001 From: jason kirtland Date: Thu, 23 Jul 2015 17:18:39 +0200 Subject: Adds Signal.send_async for asyncio --- blinker/_async.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 blinker/_async.py (limited to 'blinker/_async.py') diff --git a/blinker/_async.py b/blinker/_async.py new file mode 100644 index 0000000..5a88f13 --- /dev/null +++ b/blinker/_async.py @@ -0,0 +1,28 @@ +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(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 + -- cgit v1.2.1 From 5936e96bb059dc766d0e87fc569f61dfb5eca963 Mon Sep 17 00:00:00 2001 From: Youri Ackx Date: Fri, 2 Oct 2020 16:59:19 +0200 Subject: Fix incorrect import statement - Attempt to import asyncio.create_task - Fallback on asyncio.ensure_future - Remove obsolete asyncio.async call --- blinker/_async.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'blinker/_async.py') diff --git a/blinker/_async.py b/blinker/_async.py index 5a88f13..2b530e4 100644 --- a/blinker/_async.py +++ b/blinker/_async.py @@ -4,9 +4,9 @@ from blinker.base import Signal try: - schedule = asyncio.ensure_future + schedule = asyncio.create_task except AttributeError: - schedule = asyncio.async + schedule = asyncio.ensure_future @asyncio.coroutine -- cgit v1.2.1