3
8ßL]ú  ã               @   s   d dl Z ddd„ZdS )é    Nc                sŠ   t jƒ ‰‡ ‡‡fdd„}ˆj||ƒ zNˆ ˆƒr0n@|dkrTx6ˆjƒ sPˆjdd� q:W nˆj|d� ˆjƒ sptdƒ‚W dˆj||dd� X dS )	a6  
    Wait until the given condition is true, re-evaluating on trait change.

    This is intended for use in multithreading situations where traits can be
    modified from a different thread than the calling thread.

    Wait until `condition` is satisfied.  Raise a RuntimeError if
    `condition` is not satisfied within the given timeout.

    `condition` is a callback function that will be called with `obj`
    as its single argument.  It should return a boolean indicating
    whether the condition is satisfied or not.

    `timeout` gives the maximum time in seconds to wait for the
    condition to become true.  The default value of `None` indicates
    no timeout.

    (obj, trait) give an object and trait to listen to for indication
    of a possible change: whenever the trait changes, the condition is
    re-evaluated.  The condition will also be evaluated on entering
    this function.

    Note that in cases of unusual timing it's possible for the condition to be
    evaluated one more time *after* the ``wait_for_condition`` call has
    returned.

    c                  s   ˆ ˆƒrˆj ƒ  d S )N)Úset© )Ú	conditionÚcondition_satisfiedÚobjr   ú@/tmp/pip-install-5sebvq2j/traits/traits/util/async_trait_wait.pyÚhandler"   s    z#wait_for_condition.<locals>.handlerNgš™™™™™©?)Útimeoutz Timed out waiting for condition.T)Úremove)Ú	threadingÚEventZon_trait_changeÚis_setÚwaitÚRuntimeError)r   r   Ztraitr	   r   r   )r   r   r   r   Úwait_for_condition   s    
r   )N)r   r   r   r   r   r   Ú<module>   s   