o
    µ3IhŽ  ã                   @   sŽ   d dl Z d dlZd dlmZmZmZmZ d dlmZ edƒZ	edƒZ
dee	eeee
f f dee	e
f fdd	„Zed
ƒZdedefdd„ZdS )é    N)ÚAnyÚCallableÚ	CoroutineÚTypeVar)Ú	ParamSpecÚPÚRÚfuncÚreturnc                    s   ‡ fdd„}|S )zŽA function decorator that converts an async function to a sync function.

    This should generally not be used in production code paths.
    c                     s~   d }zt  ¡ }W n ty   t  ¡ }t  |¡ Y nw | ¡ r&ˆ| i |¤ŽS | ˆ| i |¤Ž¡}dtdtf‡ fdd„‰ ˆ |ƒS )NÚresultr
   c                    sB   t | tƒr‡ fdd„| D ƒS t | tƒrt| ƒS t| ƒrt| ƒS | S )Nc                    s   g | ]}ˆ |ƒ‘qS © r   )Ú.0Úr©Úconvert_resultr   ú\/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/chromadb/utils/async_to_sync.pyÚ
<listcomp>    s    zOasync_to_sync.<locals>.sync_wrapper.<locals>.convert_result.<locals>.<listcomp>)Ú
isinstanceÚlistÚobjectÚasync_class_to_syncÚcallableÚasync_to_sync)r   r   r   r   r      s   

z;async_to_sync.<locals>.sync_wrapper.<locals>.convert_result)ÚasyncioÚget_event_loopÚRuntimeErrorÚnew_event_loopÚset_event_loopÚ
is_runningÚrun_until_completer   )ÚargsÚkwargsÚloopr   ©r	   r   r   Úsync_wrapper   s   þz#async_to_sync.<locals>.sync_wrapperr   )r	   r$   r   r#   r   r      s   r   ÚTÚclsc                 C   sD   t  | ¡D ]\}}t|ƒrt  |¡r| d¡st| |t|ƒƒ q| S )z˜A decorator that converts a class with async methods to a class with sync methods.

    This should generally not be used in production code paths.
    Ú__)ÚinspectÚ
getmembersr   ÚiscoroutinefunctionÚ
startswithÚsetattrr   )r&   ÚattrÚvaluer   r   r   r   2   s   ÿþý€r   )r(   r   Útypingr   r   r   r   Útyping_extensionsr   r   r   r   r%   r   r   r   r   r   Ú<module>   s    ,$