U
    Ôðcc  ã                   @   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eg ee f eed
f dœ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   úb/var/www/html/project/venv/lib/python3.8/site-packages/prompt_toolkit/eventloop/async_generator.pyr      s   r   N)Úget_iterableÚreturnc                   sv   d‰t ƒ ‰ tƒ ‰tƒ ‰ddœ‡ ‡‡‡‡fdd„}t|ƒ}z(ˆ ¡ I dH }t|t ƒrVq^q:|V  q:W 5 d‰|I dH  X dS )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.
    FN)r   c               
      s<   z&ˆƒ D ]} ˆr q$ˆ  ˆj| ¡ qW 5 ˆ  ˆjˆ ¡ X dS )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ÚqZquittingr   r   Úrunner%   s    
z,generator_to_async_generator.<locals>.runnerT)r   r   r	   r
   ÚgetÚ
isinstance)r   r   Z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   ÿ
þ