U
    Acj]  ć                   @   s"   d Z ddlmZ G dd dZdS )z°
Experimental optimization

This module provides a single mixin class which allows protocols to
collapse numerous small writes into a single larger one.

@author: Jp Calderone
é    )Śreactorc                   @   s<   e Zd ZdZdZdZdZdd Zdd Zdd	 Z	d
d Z
dS )ŚBufferingMixinz+
    Mixin which adds write buffering.
    Ng        c                 C   s   t  | j| j”S ©N)r   Z	callLaterŚDELAYŚflush©Śself© r	   ś7/tmp/pip-unpacked-wheel-nrvc_22y/twisted/conch/mixin.pyŚschedule   s    zBufferingMixin.schedulec                 C   s   |  | j” d S r   )Śresetr   )r   Śtokenr	   r	   r
   Ś
reschedule   s    zBufferingMixin.reschedulec                 C   s8   | j dkrg | _|  ” | _ n|  | j ” | j |” dS )a  
        Buffer some bytes to be written soon.

        Every call to this function delays the real write by C{self.DELAY}
        seconds.  When the delay expires, all collected bytes are written
        to the underlying transport using L{ITransport.writeSequence}.
        N)Ś_delayedWriteCallŚdatar   r   Śappend)r   r   r	   r	   r
   Śwrite!   s
    
zBufferingMixin.writec                 C   s   d| _ | j | j” d| _dS )z/
        Flush the buffer immediately.
        N)r   Ś	transportZwriteSequencer   r   r	   r	   r
   r   0   s    zBufferingMixin.flush)Ś__name__Ś
__module__Ś__qualname__Ś__doc__r   r   r   r   r   r   r   r	   r	   r	   r
   r      s   r   N)r   Ztwisted.internetr   r   r	   r	   r	   r
   Ś<module>   s   	