
    Vh                        d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ  G d	 d
e      Zej                   Z e
e       G d d             ZddZy)z>
Implementation of an in-memory worker that defers execution.
    )annotations)Enumauto)CallableLiteral)implementer   )Quit)IExclusiveWorkerc                      e Zd Z e       Zy)NoMoreN)__name__
__module____qualname__r   Work     H/home/dcms/DCMS/lib/python3.12/site-packages/twisted/_threads/_memory.pyr   r      s	    6Dr   r   c                  2    e Zd ZdZef	 	 	 ddZddZddZy)	MemoryWorkerz|
    An L{IWorker} that queues work for later performance.

    @ivar _quit: a flag indicating
    @type _quit: L{Quit}
    c                :    t               | _         |       | _        y)z+
        Create a L{MemoryWorker}.
        N)r
   _quit_pending)selfpendings     r   __init__zMemoryWorker.__init__$   s     V
	r   c                n    | j                   j                          | j                  j                  |       y)z}
        Queue some work for to perform later; see L{createMemoryWorker}.

        @param work: The work to perform.
        N)r   checkr   append)r   works     r   dozMemoryWorker.do.   s&     	

T"r   c                v    | j                   j                          | j                  j                  t               y)z#
        Quit this worker.
        N)r   setr   r   
NoMoreWork)r   s    r   quitzMemoryWorker.quit7   s$     	

Z(r   N)r   z?Callable[[], list[Callable[[], object] | Literal[NoMore.Work]]]returnNone)r    zCallable[[], object]r&   r'   )r&   r'   )r   r   r   __doc__listr   r!   r%   r   r   r   r   r      s/     TX"P" 
"#)r   r   c                 ,    dfd} t               | fS )z
    Create an L{IWorker} that does nothing but defer work, to be performed
    later.

    @return: a worker that will enqueue work to perform later, and a callable
        that will perform one element of that work.
    c                     j                   syj                   d   } | t        u ryj                   j                  d        |         y)NFr   T)r   r$   pop)peekworkers    r   performz#createMemoryWorker.<locals>.performH   s@    q!:Ar   )r&   bool)r   )r/   r.   s    @r   createMemoryWorkerr1   ?   s     ^FGr   N)r&   z'tuple[MemoryWorker, Callable[[], bool]])r(   
__future__r   enumr   r   typingr   r   zope.interfacer   _conveniencer
   	_ithreadsr   r   r   r$   r   r1   r   r   r   <module>r8      sZ   
 #  $ &  'T  [[
  )  )  )Fr   