
    i                     ^    d Z ddlZddlmZ ddlmZmZ ddlmZ ddl	m
Z
 ddlmZ d	gZd
 ZdS )z"
Asyncio compatibility functions.
    N)GreenletExit   )spawn
getcurrent)Event)get_hub)Hubspawn_for_awaitablec                      t          t                      t                    st          d           fd}t	          |          S )a  
    Take a coroutine or some other object that can be awaited
    (``asyncio.Future``, ``asyncio.Task``), and turn it into a ``GreenThread``.

    Known limitations:

    * The coroutine/future/etc.  don't run in their own
      greenlet/``GreenThread``.
    * As a result, things like ``eventlet.Lock``
      won't work correctly inside ``async`` functions, thread ids aren't
      meaningful, and so on.
    zmThis API only works with eventlet's asyncio hub. To use it, set an EVENTLET_HUB=asyncio environment variable.c                  >   t          j        t          j                              fd} t                                          |            t                                          fd                                                                            S )N)loopc                 |    	 |                                   d S # t          $ r                                  Y d S w xY w)N)waitr   cancel)gthreadfutures    ;/usr/local/lib/python3.11/dist-packages/eventlet/asyncio.py_got_resultz6spawn_for_awaitable.<locals>._run.<locals>._got_result(   sG            s    ;;c                 .                         d          S )NT)send)_
has_results    r   <lambda>z3spawn_for_awaitable.<locals>._run.<locals>.<lambda>2   s    :??4+@+@     )	asyncioensure_futureget_running_loopr   linkr   add_done_callbackr   result)r   r   r   	coroutines    @@r   _runz!spawn_for_awaitable.<locals>._run#   s    &yw7O7Q7QRRR	  	  	  	  	  	+&&& WW
  !@!@!@!@AAA }}r   )
isinstancer   
AsyncioHubRuntimeErrorr   )r!   r"   s   ` r   r
   r
      sZ     gii,, 
M
 
 	

    , ;;r   )__doc__r   greenletr   greenthreadr   r   eventr   hubsr   hubs.asyncior	   r$   __all__r
    r   r   <module>r.      s      ! ! ! ! ! ! * * * * * * * *             + + + + + + 
!) ) ) ) )r   