Skip to content

Commit

Permalink
Events - Add return_handler to queue
Browse files Browse the repository at this point in the history
  • Loading branch information
jaobernardi committed Aug 11, 2023
1 parent ed12cfc commit c8b4e9b
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions pyding/event_space.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import asyncio
from queue import Queue
from typing import Union
from .structures import EventHandler, EventCall, WaitingHandler, QueuedHandler

class EventSpace:
Expand Down Expand Up @@ -47,10 +49,11 @@ def unregister_from_module(self, module):
def unregister_handler(self, handler):
self.events[handler.event][handler.priority].remove(handler)

def queue(self, event_name: str, priority: int=0, register_ra: bool=True, function: bool=None, requirement_exceptions: bool=False, is_async: bool=None, **kwargs):
def queue(self, event_name: str, priority: int=0, register_ra: bool=True, function: bool=None, requirement_exceptions: bool=False, is_async: bool=None, return_handler: bool = None, **kwargs)\
-> Union[QueuedHandler, Queue]:
handler = QueuedHandler(event_name, priority, self, is_async=is_async, requirement_exceptions=requirement_exceptions, execution_requirements=kwargs)
handler.register()
return handler.get_queue()
return handler.get_queue() if not return_handler else handler

def wait_for(self, event_name: str, priority: int=0, register_ra: bool=True, function: bool=None, requirement_exceptions: bool=False, is_async: bool=None, **kwargs):
handler = WaitingHandler(event_name, priority, self, is_async=is_async, requirement_exceptions=requirement_exceptions, execution_requirements=kwargs)
Expand Down

0 comments on commit c8b4e9b

Please sign in to comment.