Last active
July 19, 2020 18:47
-
-
Save walison17/5dfc9b696cda14aad1251727e5b45ffb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from collections import defaultdict | |
from typing import Callable | |
REGISTRY: defaultdict = defaultdict(list) | |
def channel_handler(channel: str) -> Callable: | |
def decorator(func: Callable) -> Callable: | |
REGISTRY[channel].append(func) | |
return func | |
return decorator | |
def run_handlers(notify: Notify) -> None: | |
handlers = REGISTRY.get(notify.channel, []) | |
if not handlers: | |
return | |
for handler in handlers: | |
handler(payload=notify.payload) | |
@channel_handler('top_score') | |
def notify_customers(payload: dict) -> None: | |
... | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment