
    f]                        U d Z ddlmZ ddlmZ ddlmZ ddlmZm	Z	m
Z
 ddlmZmZmZmZmZ ddlmZ d	d
gZ edeedf         Ze	 	 	 	 dd       ZdZded<    ed      Z G d d      Zef	 	 	 	 	 ddZy)z&
Implementation for async generators.
    )annotations)get_running_loop)asynccontextmanager)EmptyFullQueue)AnyAsyncGeneratorCallableIterableTypeVar   )run_in_executor_with_contextaclosinggenerator_to_async_generator_T_GeneratorN)boundc                  K   	 |  | j                          d{    y7 # | j                          d{  7   w xY ww)z1Similar to `contextlib.aclosing`, in Python 3.10.N)aclose)things    c/var/www/cvtools/html/venv/lib/python3.12/site-packages/prompt_toolkit/eventloop/async_generator.pyr   r      s.     
llnellns(   A$ A"A?;?Ai  intDEFAULT_BUFFER_SIZE_Tc                      e Zd Zy)_DoneN)__name__
__module____qualname__     r   r   r   1   s    r!   r   c               f   K   dt        |      t               }d fd}t        |      }	 	 	 j                         }t        |t              rn| (	 d| d{    y# t        $ r( |j                  dj                         d{  7  }Y Uw xY w7 9# d| d{  7   w xY ww)a]  
    Turn a generator or iterable into an async generator.

    This works by running the generator in a background thread.

    :param get_iterable: Function that returns a generator or iterable when
        called.
    :param buffer_size: Size of the queue between the async consumer and the
        synchronous generator that produces items.
    F)maxsizec                 
   	         D ]8  } r 	 	 j                  t               d       y	 	 j                  | d       : 	 	 	 j                  t               d       y# t        $ r rY yY cw xY w# t        $ r8 r3Y  	 	 j                  t               d       y# t        $ r rY yY -w xY wY w xY w# t        $ r rY yY w xY w# 	 	 j                  t               d       w # t        $ r	 rY  Y yY /w xY wxY w)z~
        Consume the generator in background thread.
        When items are received, they'll be pushed to the queue.
        r   )timeoutN)putr   r   )itemget_iterableqquittings    r   runnerz,generator_to_async_generator.<locals>.runnerH   sF   
	$   EE%'1E- ' dA. " EE%'1E-      !#" EE%'1E-    !!   EE%'1E-   s   C A$ C A7C B; $A43A47B8C B" "B21B25C 7B88C ;C
CDC-,D-C?8D<D>C??DTN)returnNone)	r   r   r   
get_nowaitr   run_in_executorget
isinstancer   )r(   buffer_sizeloopr+   runner_fr'   r)   r*   s   `     @@r   r   r   5   s      H 5ADD ,F3H?||~ $&
      ?!11$>>>? 		  si   ,B1B A) B B1#B$B1)(BBBB BB B1B.'B*(B..B1)r   r   r,   z"AsyncGenerator[_T_Generator, None])r(   zCallable[[], Iterable[_T]]r2   r   r,   zAsyncGenerator[_T, None])__doc__
__future__r   asyncior   
contextlibr   queuer   r   r   typingr	   r
   r   r   r   utilsr   __all__r   r   r   __annotations__r   r   r   r    r!   r   <module>r>      s    # $ * $ $ C C / "
 ~^CI-FG ' *   S T]	 	 +H,HH Hr!   