
    pi                     6    d Z ddlmZ ddlmZ deded   fdZy)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               r)dt         t           ddf fd} j                  |       S j	                  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                     	 j                          j                  d        y # t        $ r}j                  |       Y d }~y d }~ww xY w)N)result
set_result	Exceptionset_exception)r   emasked_futurer   s     r/opt/services/ai/voice_agent/venv/lib/python3.12/site-packages/torch/distributed/checkpoint/_experimental/utils.pyon_completez wrap_future.<locals>.on_complete   sC    /&&(((. /++A../s   !% 	A	AA	)r   
isinstancer   add_done_callbackr   )r   r   r   s   ` @r   wrap_futurer      s[     #)(M/6*	/6#; 	/4 	/ 	))+6
  	  &    )__doc__concurrent.futuresr   typingr   r    r   r   <module>r      s)    &   r   