U
    ڲg|
                     @  sZ  U d Z ddlm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mZ ejZded< d	Zded
< edZe
rejZded< ejZded< n<G dd deZG dd dejedZG dd dejedZG dd dee ZG dd dee Zd+dddd	dddZd,dddddd d!Zdd"d#d$d%d&d'd(Zdd"dd$d%d&d)d*ZdS )-z
Utilities to ease the differences between async and sync code.

These object offer a similar interface between sync and async versions; the
script async_to_sync.py will replace the async names with the sync names
when generating the sync version.
    )annotationsN)AnyCallable	CoroutineTYPE_CHECKING   )	TypeAliasTypeVarr   Workerzasyncio.Task[None]AWorkerT_GQueue_AGQueuec                   @  s   e Zd Zdd ZdS )FakeGenericMetac                 C  s   | S )N )selfitemr   r   4/tmp/pip-unpacked-wheel-b_ea6rx_/psycopg/_acompat.py__getitem__!   s    zFakeGenericMeta.__getitem__N)__name__
__module____qualname__r   r   r   r   r   r       s   r   c                   @  s   e Zd ZdS )r   Nr   r   r   r   r   r   r   r   $   s   )	metaclassc                   @  s   e Zd ZdS )r   Nr   r   r   r   r   r   '   s   c                      s,   e Zd ZdZd
dddd fdd	Z  ZS )Queuez>
    A Queue subclass with an interruptible get() method.
    TNboolfloat | Noner   )blocktimeoutreturnc                   s   |d krd}t  j||dS )Ng     @)r   r   )superget)r   r   r   	__class__r   r   r!   0   s    z	Queue.get)TN)r   r   r   __doc__r!   __classcell__r   r   r"   r   r   +   s   r   c                   @  s   e Zd ZdS )AQueueNr   r   r   r   r   r&   7   s   r&   r   z(Callable[..., Coroutine[Any, Any, None]]ztuple[Any, ...]z
str | None)fargsnamer   c                 C  s   t j| | |dS )z,
    Equivalent to asyncio.create_task.
    )r)   )asyncioZcreate_task)r'   r(   r)   r   r   r   aspawn;   s    r+   zCallable[..., Any]zthreading.Threadc                 C  s   t j| ||dd}|  |S )z=
    Equivalent to creating and running a daemon thread.
    T)targetr(   r)   daemon)	threadingThreadstart)r'   r(   r)   tr   r   r   spawnF   s    r2   r   zasyncio.Task[Any]r   None)tasksr   r   c                   s\   t j| }z2| dk	r0t jt || dI dH  n
|I dH  W n t jk
rR   Y nX dS dS )7
    Equivalent to asyncio.gather or Thread.join()
    Nr3   )r*   gatherwait_forZshieldTimeoutError)r   r5   waitr   r   r   agatherS   s    
r;   c                 G  s"   |D ]}|  sq||  qdS )r6   N)is_alivejoin)r   r5   r1   r   r   r   r7   c   s    r7   )r   N)r   N)r$   
__future__r   queuer*   r.   typingr   r   r   r   _compatr   r	   r/   r
   __annotations__r   r   r   r   r   typer   r&   r+   r2   r;   r7   r   r   r   r   <module>   s2   
    