diff --git a/sanic/mixins/signals.py b/sanic/mixins/signals.py index 2d34f838a3..dceefb1764 100644 --- a/sanic/mixins/signals.py +++ b/sanic/mixins/signals.py @@ -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 diff --git a/tests/test_signals.py b/tests/test_signals.py index a2e8669576..d06508f9cd 100644 --- a/tests/test_signals.py +++ b/tests/test_signals.py @@ -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(*_): ...