mirror of
https://github.com/beak-insights/felicity-lims.git
synced 2025-02-23 00:12:54 +08:00
19 lines
372 B
Python
19 lines
372 B
Python
|
from typing import Callable
|
||
|
|
||
|
subscribers = dict()
|
||
|
|
||
|
|
||
|
def subscribe(event_type: str, fn: Callable):
|
||
|
if not event_type in subscribers:
|
||
|
subscribers[event_type] = []
|
||
|
|
||
|
subscribers[event_type].append(fn)
|
||
|
|
||
|
|
||
|
def post_event(event_type: str, **kwargs):
|
||
|
if not event_type in subscribers:
|
||
|
return
|
||
|
|
||
|
for fn in subscribers[event_type]:
|
||
|
fn(**kwargs)
|