
    &`iE                         d dl Z d dlmZmZmZmZmZmZmZm	Z	 d dl
Z
eegdf         Zeegdf         Z G d d          ZdS )    N)AnyCallableDictIterableOptionalSetTupleUnionc                   L   e Zd ZdZddefdZ	 	 ddej        dee	         dee
         fd	Z	 	 dd
eej                 dee	         dee
         fdZdej        fdZdeej                 fdZedefd            Zdej        fdZ	 	 ddeeeef                  dee         fdZdS )RayEventManageraO  Event manager for Ray futures.

    The event manager can be used to track futures and invoke callbacks when
    they resolve.

    Futures are tracked with :meth:`track_future`. Future can then be awaited with
    :meth:`wait`. When futures successfully resolve, they trigger an optional
    ``on_result`` callback that can be passed to :meth:`track_future`. If they
    fail, they trigger an optional ``on_error`` callback.

    Args:
        shuffle_futures: If True, futures will be shuffled before awaited. This
            will avoid implicit prioritization of futures within Ray.
    Tshuffle_futuresc                 "    || _         i | _        d S N)_shuffle_futures_tracked_futures)selfr   s     }/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/ray/air/execution/_internal/event_manager.py__init__zRayEventManager.__init__   s     /
  	    Nfuture	on_resulton_errorc                     ||f| j         |<   dS )a  Track a single future and invoke callbacks on resolution.

        Control has to be yielded to the event manager for the callbacks to
        be invoked, either via :meth:`wait` or via :meth:`resolve_future`.

        Args:
            future: Ray future to await.
            on_result: Callback to invoke when the future resolves successfully.
            on_error: Callback to invoke when the future fails.

        N)r   )r   r   r   r   s       r   track_futurezRayEventManager.track_future"   s    " *3H(=f%%%r   futuresc                 @    |D ]}|                      |||           dS )a  Track multiple futures and invoke callbacks on resolution.

        Control has to be yielded to the event manager for the callbacks to
        be invoked, either via :meth:`wait` or via :meth:`resolve_future`.

        Args:
            futures: Ray futures to await.
            on_result: Callback to invoke when the future resolves successfully.
            on_error: Callback to invoke when the future fails.

        )r   r   N)r   )r   r   r   r   r   s        r   track_futureszRayEventManager.track_futures5   s?    "  	N 	NFf	HMMMM	N 	Nr   c                 <    | j                             |d           dS )zRemove future from tracking.

        The future will not be awaited anymore, and it will not trigger any callbacks.

        Args:
            future: Ray futures to discard.
        N)r   pop)r   r   s     r   discard_futurezRayEventManager.discard_futureI   s#     	!!&$/////r   returnc                 *    t          | j                  S )z)Get futures tracked by the event manager.)setr   r   s    r   get_futureszRayEventManager.get_futuresS       4()))r   c                 *    t          | j                  S r   )lenr   r$   s    r   num_futureszRayEventManager.num_futuresW   r&   r   c                 (   	 | j                             |          \  }}n&# t          $ r}t          d| d          |d}~ww xY w	 t	          j        |          }|r ||           dS dS # t          $ r}|r ||           n|Y d}~dS d}~ww xY w)a  Resolve a single future.

        This method will block until the future is available. It will then
        trigger the callback associated to the future and the event (success
        or error), if specified.

        Args:
            future: Ray future to resolve.

        zFuture z' is not tracked by this RayEventManagerN)r   r   KeyError
ValueErrorrayget	Exception)r   r   r   r   eresults         r   resolve_futurezRayEventManager.resolve_future[   s    	"&"7";";F"C"CIxx 	 	 	I&III 	
		"WV__F  "	&!!!!!" "  	 	 	  	s*     
A>AA, ,
B6BB   timeoutnum_resultsc                 "   t          |                                           }| j        rt          j        |           |pt          |          }t          j        t          |          ||          \  }}|D ]}|                     |           dS )a8  Wait up to ``timeout`` seconds for ``num_results`` futures to resolve.

        If ``timeout=None``, this method will block until all `num_results`` futures
        resolve. If ``num_results=None``, this method will await all tracked futures.

        For every future that resolves, the respective associated callbacks will be
        invoked.

        Args:
            timeout: Timeout in second to wait for futures to resolve.
            num_results: Number of futures to await. If ``None``, will wait for
                all tracked futures to resolve.

        )r4   num_returnsN)	listr%   r   randomshuffler(   r-   waitr2   )r   r4   r5   r   ready_r   s          r   r;   zRayEventManager.waitx   s    & t''))**  	$N7###!1S\\8DMM7TTTq 	( 	(F''''	( 	(r   )T)NN)Nr3   )__name__
__module____qualname____doc__boolr   r-   	ObjectRefr   _ResultCallback_ErrorCallbackr   r   r   r    r   r%   propertyintr)   r2   r
   floatr;    r   r   r   r   
   s              04-1	> >> O,> >*	> > > >, 04-1	N N#-(N O,N >*	N N N N(0S] 0 0 0 0*S/ * * * * *S * * * X*"S] " " " "> 04%&( (%s
+,( c]( ( ( ( ( (r   r   )r9   typingr   r   r   r   r   r   r	   r
   r-   rD   r/   rE   r   rI   r   r   <module>rK      s     M M M M M M M M M M M M M M M M M M M M 



C5$;'9+t+,J( J( J( J( J( J( J( J( J( J(r   