a
    ù!f'  ã                   @   s~   d dl mZ d dlZd dlmZ d dlmZ d dlmZ d dlmZ ej	rVd dl
mZ G dd	„ d	ejƒZG d
d„ dejƒZdS )é    )Úabsolute_importN)ÚAny)ÚUnion)Úfutures)ÚAcknowledgeStatus)ÚStreamingPullManagerc                       sR   e Zd ZdZddœ‡ fdd„Zdedœdd„Zed	œd
d„Zed	œdd„Z	‡  Z
S )ÚStreamingPullFuturea<  Represents a process that asynchronously performs streaming pull and
    schedules messages to be processed.

    This future is resolved when the process is stopped (via :meth:`cancel`) or
    if it encounters an unrecoverable error. Calling `.result()` will cause
    the calling thread to block indefinitely.
    r   )Úmanagerc                    s,   t t| ƒ ¡  || _| j | j¡ d| _d S )NF)Úsuperr   Ú__init__Ú_StreamingPullFuture__managerZadd_close_callbackÚ_on_close_callbackÚ_StreamingPullFuture__cancelled)Úselfr	   ©Ú	__class__© új/var/www/html/python-backend/venv/lib/python3.9/site-packages/google/cloud/pubsub_v1/subscriber/futures.pyr   '   s    zStreamingPullFuture.__init__)r	   Úresultc                 C   s.   |   ¡ rd S |d u r |  d¡ n
|  |¡ d S )NT)ÚdoneÚ
set_resultÚset_exception)r   r	   r   r   r   r   r   -   s
    z&StreamingPullFuture._on_close_callback©Úreturnc                 C   s   d| _ | j ¡  dS )a¡  Stops pulling messages and shutdowns the background thread consuming
        messages.

        The method always returns ``True``, as the shutdown is always initiated.
        However, if the background stream is already being shut down or the shutdown
        has completed, this method is a no-op.

        .. versionchanged:: 2.4.1
           The method does not block anymore, it just triggers the shutdown and returns
           immediately. To block until the background stream is terminated, call
           :meth:`result()` after cancelling the future.

        .. versionchanged:: 2.10.0
           The method always returns ``True`` instead of ``None``.
        T)r   r   Úclose©r   r   r   r   Úcancel8   s    
zStreamingPullFuture.cancelc                 C   s   | j S )zW
        Returns:
            ``True`` if the subscription has been cancelled.
        )r   r   r   r   r   Ú	cancelledN   s    zStreamingPullFuture.cancelled)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   Úboolr   r   Ú__classcell__r   r   r   r   r      s
   r   c                       sN   e Zd ZdZedœdd„Zedœdd„Zdeee	f e
dœ‡ fd	d
„Z‡  ZS )ÚFuturez¡This future object is for subscribe-side calls.

    Calling :meth:`result` will resolve the future by returning the message
    ID, unless an error occurs.
    r   c                 C   s   dS ©ziActions in Pub/Sub generally may not be canceled.

        This method always returns ``False``.
        Fr   r   r   r   r   r   ]   s    zFuture.cancelc                 C   s   dS r%   r   r   r   r   r   r   d   s    zFuture.cancelledN)Útimeoutr   c                    s   t ƒ j|dS )aD  Return a success code or raise an exception.

        This blocks until the operation completes successfully and
        returns the error code unless an exception is raised.

        Args:
            timeout: The number of seconds before this call
                times out and raises TimeoutError.

        Returns:
            AcknowledgeStatus.SUCCESS if the operation succeeded.

        Raises:
            concurrent.futures.TimeoutError: If the request times out.
            AcknowledgeError: If the operation did not succeed for another
                reason.
        )r&   )r
   r   )r   r&   r   r   r   r   k   s    zFuture.result)N)r   r   r    r!   r"   r   r   r   ÚintÚfloatr   r   r#   r   r   r   r   r$   V   s   r$   )Ú
__future__r   Útypingr   r   Zgoogle.cloud.pubsub_v1r   Z,google.cloud.pubsub_v1.subscriber.exceptionsr   ÚTYPE_CHECKINGZBgoogle.cloud.pubsub_v1.subscriber._protocol.streaming_pull_managerr   r$   r   r   r   r   r   Ú<module>   s   8