o
    -wiJ                     @  s   d dl mZ d dlZd dlmZmZmZ d dlmZm	Z	 er$d dl
mZ edZedZG dd	 d	eZG d
d dejee ZG dd dee ee ZdS )    )annotationsN)TYPE_CHECKINGCallableGeneric)TypeVaroverride)	interface_T_Sc                   @  s   e Zd ZdZdS )HandleAbandonedErrorz2The handle has no response and has been abandoned.N)__name__
__module____qualname____doc__ r   r   ]/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/wandb/sdk/mailbox/mailbox_handle.pyr      s    r   c                   @  sj   e Zd ZdZdddZejdd	d
ZejdddZejdddZ	ejdddZ
ejdddZdS )MailboxHandlezEA thread-safe handle that allows waiting for a response to a request.fnCallable[[_T], _S]returnMailboxHandle[_S]c                 C  s
   t | |S )aO  Returns a transformed handle.

        Methods on the returned handle call methods on this handle, but the
        response type is derived using the given function.

        Args:
            fn: A function to apply to this handle's result to get the new
                handle's result. The function should be pure and fast.
        )_MailboxMappedHandle)selfr   r   r   r   map   s   

zMailboxHandle.mapNonec                 C     dS )z>Abandon the handle, indicating it will not receive a response.Nr   r   r   r   r   abandon$       zMailboxHandle.abandonifaceinterface.InterfaceBasec                 C  r   )a  Cancel the handle, requesting any associated work to not complete.

        This automatically abandons the handle, as a response is no longer
        guaranteed.

        Args:
            iface: The interface on which to publish the cancel request.
        Nr   r   r   r   r   r   cancel(   r   zMailboxHandle.cancel	_T | Nonec                 C  r   )z#Returns the response if it's ready.Nr   r   r   r   r   check3   r   zMailboxHandle.checktimeoutfloat | Noner	   c                C  r   )a  Wait for a response or a timeout.

        Args:
            timeout: A finite number of seconds or None to never time out.
                If less than or equal to zero, times out immediately unless
                the response is available.

        Returns:
            The response if it arrives before the timeout or has already arrived.

        Raises:
            TimeoutError: If the timeout is reached.
            HandleAbandonedError: If the handle becomes abandoned.
        Nr   r   r%   r   r   r   wait_or7   r   zMailboxHandle.wait_orc                  s   dS )a  Wait for a response or timeout.

        This must run in an `asyncio` event loop.

        Args:
            timeout: A finite number of seconds or None to never time out.

        Returns:
            The response if it arrives before the timeout or has already arrived.

        Raises:
            TimeoutError: If the timeout is reached.
            HandleAbandonedError: If the handle becomes abandoned.
        Nr   r'   r   r   r   
wait_asyncH   s    zMailboxHandle.wait_asyncN)r   r   r   r   r   r   r   r    r   r   )r   r#   )r%   r&   r   r	   )r   r   r   r   r   abcabstractmethodr   r"   r$   r(   r)   r   r   r   r   r      s    

r   c                   @  s`   e Zd ZdZddd	Zedd
dZedddZedddZedddZ	edddZ
dS ) r   z=A mailbox handle whose result is derived from another handle.handleMailboxHandle[_T]r   r   r   r   c                 C  s   || _ || _d S N)_handle_fn)r   r.   r   r   r   r   __init__]   s   
z_MailboxMappedHandle.__init__c                 C  s   | j   d S r0   )r1   r   r   r   r   r   r   e   s   z_MailboxMappedHandle.abandonr   r    c                 C  s   | j | d S r0   )r1   r"   r!   r   r   r   r"   i   s   z_MailboxMappedHandle.cancel	_S | Nonec                 C  s   | j   }r| |S d S r0   )r1   r$   r2   )r   responser   r   r   r$   m   s   
z_MailboxMappedHandle.checkr%   r&   r
   c                C  s   |  | jj|dS N)r%   )r2   r1   r(   r'   r   r   r   r(   t   s   z_MailboxMappedHandle.wait_orc                  s    | j j|dI d H }| |S r6   )r1   r)   r2   )r   r%   r5   r   r   r   r)   x   s   
z_MailboxMappedHandle.wait_asyncN)r.   r/   r   r   r   r   r*   r+   )r   r4   )r%   r&   r   r
   )r   r   r   r   r3   r   r   r"   r$   r(   r)   r   r   r   r   r   Z   s    
r   )
__future__r   r,   typingr   r   r   typing_extensionsr   r   wandb.sdk.interfacer   r	   r
   	Exceptionr   ABCr   r   r   r   r   r   <module>   s    E