AsyncBlink is a small extention to Blinker and enables you to use coroutines as receivers for your signals.
Installation is simple, via pip:
$ pip install asyncblink
Usage is simple, too. Create a signal, connect some receivers to it
and then use the send()
method to trigger all receivers
from asyncblink import signal
my_signal = signal('nice-signal')
@asyncio.coroutine
def coro_receiver(sender, **kwargs):
# an expensive io operation here
return 'done'
def receiver(sender):
return 'ok'
my_signal.connect(coro_receiver)
my_signal.connect(receiver)
my_signal.send('some-sender')
To use tornado coroutines
pass a callable that schedules the execution of a future
using the parameter scheduler
:
from tornado import gen, ioloop
@gen.coroutine
def tornado_coro_receiver(sender, **kwargs):
# do something
return 'done'
def scheduler(future):
loop = ioloop.IOLoop.instance()
loop.add_future(future, lambda f: f)
return future
my_signal.connect(tornado_coro_receiver, scheduler=scheduler)
Other than that, AsyncBlink's usage is the same as Blinker, Take a look at the `Blinker documentation for further information.
Source code is hosted on github.