Add add_signal method (#2061)

This commit is contained in:
Adam Hopkins 2021-03-14 14:06:27 +02:00 committed by GitHub
parent 824f41d6e0
commit d4660d0ca7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 18 additions and 0 deletions

View File

@ -58,5 +58,14 @@ class SignalMixin:
return decorator
def add_signal(
self,
handler,
event: str,
condition: Dict[str, Any] = None,
):
self.signal(event=event, condition=condition)(handler)
return handler
def event(self, event: str):
raise NotImplementedError

View File

@ -11,6 +11,15 @@ from sanic.exceptions import InvalidSignal, SanicException
def test_add_signal(app):
def sync_signal(*_):
...
app.add_signal(sync_signal, "foo.bar.baz")
assert len(app.signal_router.routes) == 1
def test_add_signal_decorator(app):
@app.signal("foo.bar.baz")
def sync_signal(*_):
...