Skip to content

Commit

Permalink
Merge branch 'release-21.3' of github.com:sanic-org/sanic into releas…
Browse files Browse the repository at this point in the history
…e-21.3
  • Loading branch information
ahopkins committed Mar 14, 2021
2 parents e6c16be + 9e25622 commit 17c56ff
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions sanic/mixins/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,5 +58,14 @@ def decorator(handler: SignalHandler):

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
9 changes: 9 additions & 0 deletions tests/test_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@


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(*_):
...
Expand Down

0 comments on commit 17c56ff

Please sign in to comment.