
    #HJj+                        d Z ddlmZ ddlZddlmZ ddlmZ ddl	m
Z
mZ e
r
ddlmZmZmZ  ej                   e      Z G d d	e      Zy)
zCommon functionality for concurrent processing.

The main entry point is :class:`ThreadPoolExecutor`, which extends the
standard library executor with a lazy ``imap`` method.
    )annotationsN)deque)ThreadPoolExecutor)TYPE_CHECKINGAny)CallableIterableIteratorc                  2    e Zd ZdZddd	 	 	 	 	 	 	 	 	 ddZy)r   z+Subclass with a lazy consuming imap method.N   )timeoutqueued_tasks_per_workerc             '  ,  K   t               | j                  |dz   z  }}|j                  |j                  | j                  c}}dfd}	t        |ddiD ])  }
 | ||g|
        t        |      |k(  s! |	        + |r |	        |ryyw)ad  Ordered imap that consumes iterables just-in-time.

        References:
            https://gist.github.com/ddelange/c98b05437f80e4b16bf4fc20fde9c999

        Args:
            fn: Function to apply.
            *iterables: One (or more) iterable(s) to pass to fn (using zip) as positional argument(s).
            timeout: Per-future result retrieval timeout in seconds.
            queued_tasks_per_worker: Amount of additional items per worker to fetch from iterables to
                    fill the queue: this determines the total queue size.
                Setting 0 will result in a true just-in-time behaviour: when a worker finishes a task,
                    it waits until a result is consumed from the imap generator, at which point next()
                    is called on the input iterable(s) and a new task is submitted.
                Default 2 ensures there is always some work to pick up. Note that at imap startup,
                    the queue will fill up before the first yield occurs.

        Yields:
            Results of ``fn`` applied to items from ``iterables``, in input order.

        Example:
            long_generator = itertools.count()
            with ThreadPoolExecutor(42) as pool:
                result_generator = pool.imap(fn, long_generator)
                for result in result_generator:
                    print(result)
           c                 0             j                        S )z8Block until the next task is done and return the result.)result)popleftr   s   `/Users/ahmed/devFolder/claude-voice/.venv/lib/python3.12/site-packages/smart_open/concurrency.pygetz$ThreadPoolExecutor.imap.<locals>.getC   s    9##G,,    strictFN)returnr   )r   _max_workersr   appendsubmitziplen)selffnr   r   	iterablesfuturesmaxlenr   r   r   argsr   s     `        @r   imapzThreadPoolExecutor.imap   s     D  '4#4#48ORS8S#T")//7>>4;;	- 151D6"$t$%7|v%e 2
 %K s   A4B9BB)
r   zCallable[..., Any]r    zIterable[Any]r   zfloat | Noner   intr   zIterator[Any])__name__
__module____qualname____doc__r$    r   r   r   r      sB    5 !%'(// "/ 	/
 "%/ 
/r   r   )r)   
__future__r   loggingcollectionsr   concurrent.futuresr   _ThreadPoolExecutortypingr   r   collections.abcr   r	   r
   	getLoggerr&   loggerr*   r   r   <module>r4      sC    #   H %<<			8	$2, 2r   