Skip to content

Commit

Permalink
Update event_emitter.py
Browse files Browse the repository at this point in the history
  • Loading branch information
theomonnom committed Nov 7, 2024
1 parent 6ea5452 commit 97269a7
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions livekit-rtc/livekit/rtc/event_emitter.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@

from .log import logger

T = TypeVar("T")
T_contra = TypeVar("T_contra", contravariant=True)


class EventEmitter(Generic[T]):
class EventEmitter(Generic[T_contra]):
def __init__(self) -> None:
"""
Initialize a new instance of EventEmitter.
"""
self._events: Dict[T, Set[Callable]] = dict()
self._events: Dict[T_contra, Set[Callable]] = dict()

def emit(self, event: T, *args) -> None:
def emit(self, event: T_contra, *args) -> None:
"""
Trigger all callbacks associated with the given event.
Expand Down Expand Up @@ -60,7 +60,7 @@ def greet(name):
except Exception:
logger.exception(f"failed to emit event {event}")

def once(self, event: T, callback: Optional[Callable] = None) -> Callable:
def once(self, event: T_contra, callback: Optional[Callable] = None) -> Callable:
"""
Register a callback to be called only once when the event is emitted.
Expand Down Expand Up @@ -116,7 +116,7 @@ def decorator(callback: Callable) -> Callable:

return decorator

def on(self, event: T, callback: Optional[Callable] = None) -> Callable:
def on(self, event: T_contra, callback: Optional[Callable] = None) -> Callable:
"""
Register a callback to be called whenever the event is emitted.
Expand Down Expand Up @@ -168,7 +168,7 @@ def decorator(callback: Callable) -> Callable:

return decorator

def off(self, event: T, callback: Callable) -> None:
def off(self, event: T_contra, callback: Callable) -> None:
"""
Unregister a callback from an event.
Expand Down

0 comments on commit 97269a7

Please sign in to comment.