Skip to content

Commit 3e24162

Browse files
committed
Raise error if EventEmitter used with async callback
1 parent f392454 commit 3e24162

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

examples/participant_attributes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ async def main(room: rtc.Room) -> None:
2424
)
2525

2626
@room.on("participant_attributes_changed")
27-
def on_participant_attributes_changed(
27+
async def on_participant_attributes_changed(
2828
changed_attributes: dict[str, str], participant: rtc.Participant
2929
):
3030
logging.info(

livekit-rtc/livekit/rtc/event_emitter.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import inspect
2+
import asyncio
23
from typing import Callable, Dict, Set, Optional, Generic, TypeVar
34

45
from .log import logger
@@ -156,6 +157,11 @@ def greet(name):
156157
```
157158
"""
158159
if callback is not None:
160+
if asyncio.iscoroutinefunction(callback):
161+
raise ValueError(
162+
"Cannot register an async callback with `.on()`. Use `asyncio.create_task` within your synchronous callback instead."
163+
)
164+
159165
if event not in self._events:
160166
self._events[event] = set()
161167
self._events[event].add(callback)

0 commit comments

Comments
 (0)