
    '                         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                  rd dl
mZ  G d d	ej                        Z G d
 dej                        Zy)    )absolute_importN)Any)Union)futures)AcknowledgeStatus)StreamingPullManagerc                   L     e Zd ZdZd
 fdZdddefdZdefdZdefd	Z	 x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.
    managerr   c                     t         t        |           || _        | j                  j	                  | j
                         d| _        y )NF)superr
   __init___StreamingPullFuture__manageradd_close_callback_on_close_callback_StreamingPullFuture__cancelled)selfr   	__class__s     <lib/third_party/google/cloud/pubsub_v1/subscriber/futures.pyr   zStreamingPullFuture.__init__'   s8    !413 ))$*A*AB     resultc                 p    | j                         ry || j                  d       y | j                  |       y )NT)done
set_resultset_exception)r   r   r   s      r   r   z&StreamingPullFuture._on_close_callback-   s/    99; >OOD!v&r   returnc                 F    d| _         | j                  j                          y)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   s    r   cancelzStreamingPullFuture.cancel8   s    $  r   c                     | j                   S )zW
        Returns:
            ``True`` if the subscription has been cancelled.
        )r   r   s    r   	cancelledzStreamingPullFuture.cancelledN   s    
 r   )r   r   )__name__
__module____qualname____doc__r   r   r   boolr    r"   __classcell__r   s   @r   r
   r
      s9    !	'*@ 	'# 	' , 4  r   r
   c                   P     e Zd ZdZdefdZdefdZddeee	f   de
f fdZ xZS )FuturezThis 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                      yziActions in Pub/Sub generally may not be canceled.

        This method always returns ``False``.
        F r   s    r   r    zFuture.cancel]       
 r   c                      yr-   r.   r   s    r   r"   zFuture.cancelledd   r/   r   timeoutc                 $    t         |   |      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.
        )r1   )r   r   )r   r1   r   s     r   r   zFuture.resultk   s    $ w~g~..r   )N)r#   r$   r%   r&   r'   r    r"   r   intfloatr   r   r(   r)   s   @r   r+   r+   V   sB     4 /eCJ/ /;L / /r   r+   )
__future__r   typingr   r   google.cloud.pubsub_v1r   ,google.cloud.pubsub_v1.subscriber.exceptionsr   TYPE_CHECKINGBgoogle.cloud.pubsub_v1.subscriber._protocol.streaming_pull_managerr   r+   r
   r.   r   r   <module>r;      sH    '    * J	
5 '.. 5 p'/W^^ '/r   