o
    ˷e                     @   s   d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZ dgZedZG dd	 d	Zd
eg ee f deedf fddZdS )z&
Implementation for async generators.
    )Queue)AsyncGeneratorCallableIterableTypeVarUnion   )get_event_looprun_in_executor_with_contextgenerator_to_async_generator_Tc                   @   s   e Zd ZdS )_DoneN)__name__
__module____qualname__ r   r   _/var/www/ideatree/venv/lib/python3.10/site-packages/prompt_toolkit/eventloop/async_generator.pyr      s    r   get_iterablereturnNc                   s   dt   t t d fdd}t|}z	  I dH }t|t r*n|V  qW d|I dH  dS d|I dH  w )z
    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.
    Fr   Nc               
      s\   z% D ]} r
 n j|  qW  j  dS W  j  dS  j  w )z~
        Consume the generator in background thread.
        When items are received, they'll be pushed to the queue.
        N)call_soon_threadsafe
put_nowait)item_doner   loopqquittingr   r   runner%   s   
	"z,generator_to_async_generator.<locals>.runnerT)r   N)r   r   r	   r
   get
isinstance)r   r   runner_fr   r   r   r   r      s&   
)__doc__asyncior   typingr   r   r   r   r   utilsr	   r
   __all__r   r   r   r   r   r   r   <module>   s    
