listener: Speed up event emitting and improve error reporting
(cherry picked from commit 655b7badf4)
This commit is contained in:
parent
73fac53dd5
commit
d14d64cb7d
@ -17,7 +17,21 @@ def send(cls, event, **kwargs):
|
|||||||
listeners = pykka.ActorRegistry.get_by_class(cls)
|
listeners = pykka.ActorRegistry.get_by_class(cls)
|
||||||
logger.debug('Sending %s to %s: %s', event, cls.__name__, kwargs)
|
logger.debug('Sending %s to %s: %s', event, cls.__name__, kwargs)
|
||||||
for listener in listeners:
|
for listener in listeners:
|
||||||
listener.proxy().on_event(event, **kwargs)
|
# Save time by calling methods on Pykka actor without creating a
|
||||||
|
# throwaway actor proxy.
|
||||||
|
#
|
||||||
|
# Because we use `.tell()` there is no return channel for any errors,
|
||||||
|
# so Pykka logs them immediately. The alternative would be to use
|
||||||
|
# `.ask()` and `.get()` the returned futures to block for the listeners
|
||||||
|
# to react and return their exceptions to us. Since emitting events in
|
||||||
|
# practise is making calls upwards in the stack, blocking here would
|
||||||
|
# quickly deadlock.
|
||||||
|
listener.tell({
|
||||||
|
'command': 'pykka_call',
|
||||||
|
'attr_path': ('on_event',),
|
||||||
|
'args': (event,),
|
||||||
|
'kwargs': kwargs,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
class Listener(object):
|
class Listener(object):
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user