
    'jp                     f    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
dS )    N)create_taskdecorate_taskget_number_of_pending_taskshandle_task_resulttaskc                  *    t          t                    S N)lenPENDING_TASKS     X/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trame_common/exec/asynchronous.pyr   r      s    }r   r   returnc                     	 |                                   d S # t          j        $ r Y d S t          $ r t	          j        d|            Y d S w xY w)NzException raised by task = %r)resultasyncioCancelledError	Exceptionlogging	exceptionr   s    r   r   r      sq    A!    A A A94@@@@@@As    AAAc                     t                               |            |                     t                     |                     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      sI     d-...=0111Kr   c                     |L	 t          j                    }n7# t          $ r* t          j                    }t          j        |           Y nw xY wt          |                    |                     S )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   -   s|     |	))++DD 	) 	) 	))++D"4(((((	) )))44555s    1AAc                       fd}|S )z<Function decorator to make its async execution within a taskc                  2    t           | i |           d S r	   )r   )argskwargsfuncs     r   wrapperztask.<locals>.wrapperF   s&    DD$)&))*****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,      s          AW\ Ad A A A A  "6 6 6 6,    r   