# Path: evergreen/locks.py
# class Condition(object):
# 
#     def __init__(self, lock=None):
#         if lock is None:
#             lock = RLock()
#         self._lock = lock
#         self._waiters = []
# 
#         # Export the lock's acquire() and release() methods
#         self.acquire = lock.acquire
#         self.release = lock.release
#         # If the lock defines _release_save() and/or _acquire_restore(),
#         # these override the default implementations (which just call
#         # release() and acquire() on the lock).  Ditto for _is_owned().
#         try:
#             self._release_save = lock._release_save
#         except AttributeError:
#             pass
#         try:
#             self._acquire_restore = lock._acquire_restore
#         except AttributeError:
#             pass
#         try:
#             self._is_owned = lock._is_owned
#         except AttributeError:
#             pass
# 
#     def wait(self, timeout=None):
#         if not self._is_owned():
#             raise RuntimeError('cannot wait on un-acquired lock')
#         waiter = Semaphore()
#         waiter.acquire()
#         self._waiters.append(waiter)
#         saved_state = self._release_save()
#         try:
#             return waiter.acquire(timeout=timeout)
#         finally:
#             self._acquire_restore(saved_state)
# 
#     def wait_for(self, predicate, timeout=None):
#         endtime = None
#         waittime = timeout
#         result = predicate()
#         if not result:
#             self.wait(waittime)
#             result = predicate()
#         return result
# 
#     def notify(self, n=1):
#         if not self._is_owned():
#             raise RuntimeError('cannot wait on un-acquired lock')
#         _waiters = self._waiters
#         waiters = _waiters[:n]
#         for waiter in waiters:
#             waiter.release()
#             try:
#                 _waiters.remove(waiter)
#             except ValueError:
#                 pass
# 
#     def notify_all(self):
#         self.notify(len(self._waiters))
# 
#     def _acquire_restore(self, state):
#         self._lock.acquire()
# 
#     def _release_save(self):
#         self._lock.release()
# 
#     def _is_owned(self):
#         # Return True if lock is owned by current_thread.
#         # This method is called only if __lock doesn't have _is_owned().
#         if self._lock.acquire(False):
#             self._lock.release()
#             return False
#         else:
#             return True
# 
#     def __enter__(self):
#         return self._lock.__enter__()
# 
#     def __exit__(self, *args):
#         return self._lock.__exit__(*args)
# 
# class Lock(Semaphore):
# 
#     def __init__(self):
#         super(Lock, self).__init__(value=1)


from evergreen.locks import Condition, Lock
# This file is part of Evergreen. See the NOTICE for more information.
#


__all__ = ['Result']


Null = object()

class Result(object):
    """
    Result is an internal object which is meant to be used like a Future, but being more
    lightweight and supporting a single waiter. Example:

    result = Result()

    def f1():
        with result:
            some_async_func()
            return result.get()

    def some_async_func():
        # this function runs in a different task
        ...
        result.set_value(42)
    """

    __slots__ = ['_lock', '_cond', '_locked', '_used', '_exc', '_value']

    def __init__(self):

# Path: evergreen/locks.py
# class Condition(object):
# 
#     def __init__(self, lock=None):
#         if lock is None:
#             lock = RLock()
#         self._lock = lock
#         self._waiters = []
# 
#         # Export the lock's acquire() and release() methods
#         self.acquire = lock.acquire
#         self.release = lock.release
#         # If the lock defines _release_save() and/or _acquire_restore(),
#         # these override the default implementations (which just call
#         # release() and acquire() on the lock).  Ditto for _is_owned().
#         try:
#             self._release_save = lock._release_save
#         except AttributeError:
#             pass
#         try:
#             self._acquire_restore = lock._acquire_restore
#         except AttributeError:
#             pass
#         try:
#             self._is_owned = lock._is_owned
#         except AttributeError:
#             pass
# 
#     def wait(self, timeout=None):
#         if not self._is_owned():
#             raise RuntimeError('cannot wait on un-acquired lock')
#         waiter = Semaphore()
#         waiter.acquire()
#         self._waiters.append(waiter)
#         saved_state = self._release_save()
#         try:
#             return waiter.acquire(timeout=timeout)
#         finally:
#             self._acquire_restore(saved_state)
# 
#     def wait_for(self, predicate, timeout=None):
#         endtime = None
#         waittime = timeout
#         result = predicate()
#         if not result:
#             self.wait(waittime)
#             result = predicate()
#         return result
# 
#     def notify(self, n=1):
#         if not self._is_owned():
#             raise RuntimeError('cannot wait on un-acquired lock')
#         _waiters = self._waiters
#         waiters = _waiters[:n]
#         for waiter in waiters:
#             waiter.release()
#             try:
#                 _waiters.remove(waiter)
#             except ValueError:
#                 pass
# 
#     def notify_all(self):
#         self.notify(len(self._waiters))
# 
#     def _acquire_restore(self, state):
#         self._lock.acquire()
# 
#     def _release_save(self):
#         self._lock.release()
# 
#     def _is_owned(self):
#         # Return True if lock is owned by current_thread.
#         # This method is called only if __lock doesn't have _is_owned().
#         if self._lock.acquire(False):
#             self._lock.release()
#             return False
#         else:
#             return True
# 
#     def __enter__(self):
#         return self._lock.__enter__()
# 
#     def __exit__(self, *args):
#         return self._lock.__exit__(*args)
# 
# class Lock(Semaphore):
# 
#     def __init__(self):
#         super(Lock, self).__init__(value=1)


# Path: evergreen/core/utils.py
from evergreen.locks import Condition, Lock

# This file is part of Evergreen. See the NOTICE for more information.
#


__all__ = ['Result']


Null = object()

class Result(object):
    """
    Result is an internal object which is meant to be used like a Future, but being more
    lightweight and supporting a single waiter. Example:

    result = Result()

    def f1():
        with result:
            some_async_func()
            return result.get()

    def some_async_func():
        # this function runs in a different task
        ...
        result.set_value(42)
    """

    __slots__ = ['_lock', '_cond', '_locked', '_used', '_exc', '_value']

    def __init__(self):

        self._lock = Lock()