
    Ki	                     P    d Z ddlmZmZmZ ddlZ ed      Z G d dee         Zy)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                   P    e Zd ZdZddZdeddfdZdeddfdZdefd	Z	de
fd
Zy)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                 R    t        j                         | _        d | _        d | _        y )N)anyioEvent_event_value
_exceptionselfs    r/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/mcp/shared/experimental/tasks/resolver.py__init__zResolver.__init__   s    kkm $04    valuec                     | j                   j                         rt        d      || _        | j                   j	                          y)z)Set the result value and wake up waiters.Resolver already completedN)r   is_setRuntimeErrorr   set)r   r   s     r   
set_resultzResolver.set_result$   s3    ;;;<<r   excc                     | j                   j                         rt        d      || _        | j                   j	                          y)z%Set an exception and wake up waiters.r   N)r   r   r   r   r   )r   r   s     r   set_exceptionzResolver.set_exception+   s3    ;;;<<r   c                    K   | j                   j                          d{    | j                  | j                  t        t        | j
                        S 7 6w)z:Wait for the result and return it, or raise the exception.N)r   waitr   r   r   r   r   s    r   r    zResolver.wait2   sF     kk   ??&//!At{{##	 	!s   AA7Ac                 6    | j                   j                         S )z/Return True if the resolver has been completed.)r   r   r   s    r   donezResolver.done:   s    {{!!##r   )r	   N)__name__
__module____qualname____doc__r   r   r   BaseExceptionr   r    boolr"    r   r   r   r      sJ    5
 d  4 $A $$d $r   r   )r&   typingr   r   r   r   r   r   r)   r   r   <module>r+      s.    * ) CL-$wqz -$r   