o
    h.                     @  s   d dl mZ d dlZd dlZd dlZd dlZd dlmZmZm	Z	m
Z
 d dlmZ d dlZd dlZd dlZedZedZejdkrEejZndddZdddZdddZdS )    )annotationsN)AnyTypeVarCallable	Awaitable)	ParamSpecT_RetvalT_ParamSpec)   	   funcCallable[T_ParamSpec, T_Retval]argsT_ParamSpec.argskwargsT_ParamSpec.kwargsreturnr   c                  sB   t j }t }tj|j| g|R i |}|d|I dH S )a  Asynchronously run function *func* in a separate thread.

        Any *args and **kwargs supplied for this function are directly passed
        to *func*. Also, the current :class:`contextvars.Context` is propagated,
        allowing context variables from the main thread to be accessed in the
        separate thread.

        Returns a coroutine that can be awaited to get the eventual result of *func*.
        N)	asyncioeventsget_running_loopcontextvarscopy_context	functoolspartialrunrun_in_executor)r   r   r   loopctx	func_call r   e/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/groq/_utils/_sync.py_asyncio_to_thread   s
   
r!   c                  sP   t  dkrt| g|R i |I d H S tjtj| g|R i |I d H S )Nr   )sniffiocurrent_async_libraryr!   anyio	to_threadrun_syncr   r   )r   r   r   r   r   r    r%   )   s   
r%   function*Callable[T_ParamSpec, Awaitable[T_Retval]]c                   s   d
 fdd}|S )aP  
    Take a blocking function and create an async one that receives the same
    positional and keyword arguments. For python version 3.9 and above, it uses
    asyncio.to_thread to run the function in a separate thread. For python version
    3.8, it uses locally defined copy of the asyncio.to_thread function which was
    introduced in python 3.9.

    Usage:

    ```python
    def blocking_func(arg1, arg2, kwarg1=None):
        # blocking code
        return result


    result = asyncify(blocking_function)(arg1, arg2, kwarg1=value1)
    ```

    ## Arguments

    `function`: a blocking regular callable (e.g. a function)

    ## Return

    An async function that takes the same positional and keyword arguments as the
    original one, that when called runs the same original function in a thread worker
    and returns the result.
    r   r   r   r   r   r   c                    s   t  g| R i |I d H S )N)r%   )r   r   r'   r   r    wrapperS   s   zasyncify.<locals>.wrapperN)r   r   r   r   r   r   r   )r'   r*   r   r)   r    asyncify5   s   r+   )r   r   r   r   r   r   r   r   )r   r   r   r   r   r   r   r   )r'   r   r   r(   )
__future__r   sysr   r   r   typingr   r   r   r   typing_extensionsr   r$   r"   anyio.to_threadr   r	   version_infor%   r!   r+   r   r   r   r    <module>   s"    


