o
    *i	                     @   s@   d Z ddlmZmZmZ ddlZedZG dd dee ZdS )z
Resolver - An anyio-compatible future-like object for async result passing.

This provides a simple way to pass a result (or exception) from one coroutine
to another without depending on asyncio.Future.
    )GenericTypeVarcastNTc                   @   sZ   e Zd ZdZdddZdeddfddZd	eddfd
dZdefddZ	de
fddZdS )Resolverai  
    A simple resolver for passing results between coroutines.

    Unlike asyncio.Future, this works with any anyio-compatible async backend.

    Usage:
        resolver: Resolver[str] = Resolver()

        # In one coroutine:
        resolver.set_result("hello")

        # In another coroutine:
        result = await resolver.wait()  # returns "hello"
    returnNc                 C   s   t  | _d | _d | _d S )N)anyioEvent_event_value
_exceptionself r   c/home/ubuntu/veenaModal/venv/lib/python3.10/site-packages/mcp/shared/experimental/tasks/resolver.py__init__   s   

zResolver.__init__valuec                 C   &   | j  r	td|| _| j   dS )z)Set the result value and wake up waiters.Resolver already completedN)r
   is_setRuntimeErrorr   set)r   r   r   r   r   
set_result$      
zResolver.set_resultexcc                 C   r   )z%Set an exception and wake up waiters.r   N)r
   r   r   r   r   )r   r   r   r   r   set_exception+   r   zResolver.set_exceptionc                    s.   | j  I dH  | jdur| jtt| jS )z:Wait for the result and return it, or raise the exception.N)r
   waitr   r   r   r   r   r   r   r   r   2   s
   
zResolver.waitc                 C   s
   | j  S )z/Return True if the resolver has been completed.)r
   r   r   r   r   r   done:   s   
zResolver.done)r   N)__name__
__module____qualname____doc__r   r   r   BaseExceptionr   r   boolr   r   r   r   r   r      s    
r   )r!   typingr   r   r   r   r   r   r   r   r   r   <module>   s
    