Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sanic-org/sanic into signal-reser…
Browse files Browse the repository at this point in the history
…vation
  • Loading branch information
ahopkins committed Mar 14, 2021
2 parents f7dc70b + d4660d0 commit 4c38880
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 4c38880

Please sign in to comment.