
    PfF                     R    d dl Z d dlmZ  G d de          Z G d de          ZdS )    N)IBatchedTimerc                   $    e Zd ZdZd Zd Zd ZdS )_BatchedCallz
    Wraps IDelayedCall-implementing objects, implementing only the API
    which txaio promised in the first place: .cancel

    Do not create these yourself; use _BatchedTimer.call_later()
    c                 0    || _         || _        || _        d S N)_timer_index_call)selftimerindexthe_calls       ?/var/www/html/env/lib/python3.11/site-packages/txaio/_common.py__init__z_BatchedCall.__init__'   s    


    c                 T    | j                             | j        |            d | _         d S r   )r   _remove_callr	   r   s    r   cancelz_BatchedCall.cancel-   s'      d333r   c                 *    |                                  S r   )r
   r   s    r   __call__z_BatchedCall.__call__1   s    zz||r   N)__name__
__module____qualname____doc__r   r   r    r   r   r   r      sK                 r   r   c                   .    e Zd ZdZ	 ddZd Zd Zd ZdS )_BatchedTimera=  
    Internal helper.

    Instances of this are returned from
    :meth:`txaio.make_batched_timer` and that is the only way they
    should be instantiated. You may depend on methods from the
    interface class only (:class:`txaio.IBatchedTimer`)

    **NOTE** that the times are in milliseconds in this class!
    Nc                     |dk    rt          d          t          |          | _        || _        || _        || _        t                      | _        || _        d S )N        z!bucket_milliseconds must be > 0.0)	
ValueErrorfloat_bucket_milliseconds_chunk_size_get_seconds_create_delayed_calldict_buckets_loop)r   bucket_milliseconds
chunk_sizeseconds_providerdelayed_call_creatorloops         r   r   z_BatchedTimer.__init__A   sc    #%%3   %**=$>$>!%,$8!


r   c                    |                                  }t          ||z             dz  }|t          || j        z            z  }t          | |fd          }	 | j        |         d                             |           nO# t          $ rB |dz  |z
  }|                     t          d|          | j	        |          }	|	|gf| j        |<   Y nw xY w|S )z#
        IBatchedTimer API
        i  c                        i S r   r   )argsfunckwargss   r   <lambda>z*_BatchedTimer.call_later.<locals>.<lambda>V   s    TT45J65J5J r           @@r    )
r%   intr#   r   r(   appendKeyErrorr&   max_notify_bucket)
r   delayr2   r1   r3   now	real_timecalldiffdelayed_calls
     ```     r   
call_laterz_BatchedTimer.call_laterN   s   
 !!e$$t+	ST%>>???	D)-J-J-J-J-J-JKK	>M)$Q'..t4444 
	> 
	> 
	>&#-D  44C#Y L )5tf'=DM)$$$
	> s   &B A	CCc                 
     j         |         \  }} j         |= g  fd j        t          j        t	          t          |                     j        z            z  } | j        t          d|                     dS )z
        Internal helper. This 'does' the callbacks in a particular bucket.

        :param real_time: the bucket to do callbacks on
        c                 ^   | d |         D ]9}	  |             # t           $ r}                    |           Y d }~2d }~ww xY w| |d          } | r                    |dz  | ||           d S t                    r.d}D ]}|d                    |          z  }t          |          d S )Nr6   z'Error(s) processing call_later bucket:
z{}
)	Exceptionr8   r&   lenformatRuntimeError)	callsr+   chunk_delay_msr?   emsgerrorsnotify_one_chunkr   s	         r   rN   z6_BatchedTimer._notify_bucket.<locals>.notify_one_chunkp   s
   kzk* % %%DFFFF  % % %MM!$$$$$$$$%*++&E ,))"V+$eZ     v;; ,DC# 0 0v}}Q///&s+++	, ,s   

A>Ar    N)r(   r#   mathceilr"   rF   r$   r:   )r   r>   rA   rI   delay_msrM   rN   s   `    @@r   r;   z_BatchedTimer._notify_bucketf   s     !%i 8uM)$	, 	, 	, 	, 	, 	, 	,* ,tys5zz9J9JTM]9]/^/^^ 	 0#c82D2DEEEEEr   c                     	 | j         |         \  }}n# t          $ r Y dS w xY w|                    |           |s| j         |= |                                 dS dS )z
        Internal helper. Removes a (possibly still pending) call from a
        bucket. It is *not* an error of the bucket is gone (e.g. the
        call has already happened).
        N)r(   r9   remover   )r   r>   r?   rA   rI   s        r   r   z_BatchedTimer._remove_call   s    	$(M)$<!\55 	 	 	FF	
 	T 	"i(!!!!!	" 	"s    
!!r   )r   r   r   r   r   rB   r;   r   r   r   r   r   r   5   si        	 	 ?C     0"F "F "FH" " " " "r   r   )rO   txaio.interfacesr   objectr   r   r   r   r   <module>rV      s   6  * * * * * *    6   ,e" e" e" e" e"M e" e" e" e" e"r   