
    `i                     >    d Z ddlmZ ddlmZ deded         fdZdS )z
Utility functions for the experimental checkpoint module.

This module contains helper functions and utilities used across the experimental
checkpoint functionality.
    )Future)Anyoriginal_resultreturnNc                      t                      t           t                     r1dt           t                   ddf fd}                     |           n                    d           S )a  
    Wraps a result (Future or not) to return a Future with None result.

    If the input is a Future, returns a new Future that completes with None when
    the original Future completes successfully, or propagates any exception.
    If the input is not a Future, returns a completed Future with None result.

    Args:
        original_result: The result to wrap (Future or any other value).

    Returns:
        A Future that completes with None on success or propagates exceptions.
    _r   Nc                     	                                                       d            d S # t          $ r }                    |           Y d }~d S d }~ww xY w)N)result
set_result	Exceptionset_exception)r   emasked_futurer   s     /home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/torch/distributed/checkpoint/_experimental/utils.pyon_completez wrap_future.<locals>.on_complete   sy    /&&(((((..... / / /++A........./s   ). 
AAA)r   
isinstancer   add_done_callbackr   )r   r   r   s   ` @r   wrap_futurer      s     #)((M/6** '	/6#; 	/4 	/ 	/ 	/ 	/ 	/ 	/ 	/ 	))+6666 	  &&&    )__doc__concurrent.futuresr   typingr   r    r   r   <module>r      se     & % % % % %             r   