
    hjp                     h    d dl Z d dlZg dZ e       Zd Zde j                  ddfdZd Zd
dZ	d	 Z
y)    N)create_taskdecorate_taskget_number_of_pending_taskshandle_task_resulttaskc                       t        t              S N)lenPENDING_TASKS     K/DATA/.local/lib/python3.12/site-packages/trame_common/exec/asynchronous.pyr   r      s    }r   r   returnc                     	 | j                          y # t        j                  $ r Y y t        $ r t	        j
                  d|        Y y w xY w)NzException raised by task = %r)resultasyncioCancelledError	Exceptionlogging	exceptionr   s    r   r   r      sD    A!!  A94@As    A	A	A	c                     t         j                  |        | j                  t               | j                  t         j                         | S )a  
    Decorate a task by attaching a done callback so any exception or error could
    be caught and reported.

    :param task: A coroutine to execute as an independent task
    :type task: asyncio.Task

    :return: The same task object
    :rtype: asyncio.Task
    )r   addadd_done_callbackr   discardr   s    r   r   r      s:     d-.=001Kr   c                     |	 t        j                         }t        |j                  |             S # t        $ r, t        j                         }t        j                  |       Y Nw xY w)a  
    Create a task from a coroutine while also attaching a done callback so any
    exception or error could be caught and reported.

    :param coroutine: A coroutine to execute as an independent task
    :param loop: Optionally provide the loop on which the task should be
                 scheduled on. By default we will use the current running loop.

    :return: The decorated task
    :rtype: asyncio.Task
    )r   get_event_loopRuntimeErrornew_event_loopset_event_loopr   r   )	coroutineloops     r   r   r   -   sa     |	)))+D
 )))455	  	)))+D""4(	)s   2 2A'&A'c                       fd}|S )z<Function decorator to make its async execution within a taskc                  (    t         | i |       y r	   )r   )argskwargsfuncs     r   wrapperztask.<locals>.wrapperF   s    D$)&)*r   r   )r'   r(   s   ` r   r   r   C   s    + Nr   r	   )r   r   __all__setr   r   Taskr   r   r   r   r   r   r   <module>r,      sI      AW\\ Ad A"6,r   