@@ -50,8 +50,6 @@ def add_handler(self, *args, order: float = 0) -> Callable:
5050
5151 Arguments:
5252 callback (callable, optional): The event handler. Must accept a single event argument.
53- Can be a plain function or a coroutine function.
54- If you use async callbacks, see :ref:`async` for the limitations.
5553 *types (list of EventType): A list of event types.
5654 order (float): Set callback priority order. Callbacks with lower priorities
5755 are called first. Default is 0. When an event is emitted, callbacks with
@@ -113,6 +111,10 @@ def decorator(_callback: Callable):
113111 return decorator (callback )
114112
115113 def _add_handler (self , callback , order , * types ):
114+ if iscoroutinefunction (callback ):
115+ raise TypeError (
116+ "Coroutines cannot be callbacks (anymore). Instead, you can use a regular callback that calls `loop.add_task(coro)`."
117+ )
116118 if self ._closed :
117119 return
118120 self .remove_handler (callback , * types )
@@ -166,7 +168,7 @@ def submit(self, event):
166168
167169 self ._pending_events .append (event )
168170
169- async def flush (self ):
171+ def flush (self ):
170172 """Dispatch all pending events.
171173
172174 This should generally be left to the scheduler.
@@ -176,9 +178,9 @@ async def flush(self):
176178 event = self ._pending_events .popleft ()
177179 except IndexError :
178180 break
179- await self .emit (event )
181+ self .emit (event )
180182
181- async def emit (self , event ):
183+ def emit (self , event ):
182184 """Directly emit the given event.
183185
184186 In most cases events should be submitted, so that they are flushed
@@ -192,15 +194,12 @@ async def emit(self, event):
192194 if event .get ("stop_propagation" , False ):
193195 break
194196 with log_exception (f"Error during handling { event_type } event" ):
195- if iscoroutinefunction (callback ):
196- await callback (event )
197- else :
198- callback (event )
197+ callback (event )
199198 # Close?
200199 if event_type == "close" :
201200 self ._release ()
202201
203- async def close (self ):
202+ def close (self ):
204203 """Close the event handler.
205204
206205 Drops all pending events, send the close event, and disables the emitter.
@@ -209,4 +208,4 @@ async def close(self):
209208 if not self ._closed :
210209 self ._pending_events .clear ()
211210 self .submit ({"event_type" : "close" })
212- await self .flush ()
211+ self .flush ()
0 commit comments