Support for event filter on functional hook

This commit is contained in:
Fabio Manganiello 2020-04-09 00:09:36 +02:00
parent 0dae03551f
commit d46385687f
1 changed files with 17 additions and 14 deletions

View File

@ -165,12 +165,13 @@ class EventHook(object):
threading.Thread(target=_thread_func, name='Event-' + self.name, args=(result,)).start()
def hook(f, event_type=Event, **condition):
def hook(event_type=Event, **condition):
def wrapper(f):
f.hook = True
f.condition = EventCondition(type=event_type, **condition)
@wraps(f)
def _execute_hook(*args, **kwargs):
def wrapped(*args, **kwargs):
from platypush import Response
try:
@ -182,7 +183,9 @@ def hook(f, event_type=Event, **condition):
except Exception as e:
return Response(errors=[str(e)])
return _execute_hook
return wrapped
return wrapper
# vim:sw=4:ts=4:et: