Skip to content

Commit

Permalink
Add add_signal method (#2061)
Browse files Browse the repository at this point in the history
  • Loading branch information
ahopkins authored Mar 14, 2021
1 parent 824f41d commit d4660d0
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 d4660d0

Please sign in to comment.