# Path: rx/concurrency.py
# class Atomic:
#   def __init__(self, value=None, lock=RLock()):
#     self.lock = lock
#     self._value = value
# 
#   def value():
#       doc = "The value property."
#       def fget(self):
#           return self._value
#       def fset(self, value):
#           self.exchange(value)
#       return locals()
#   value = property(**value())
# 
#   def exchange(self, value):
#     with self.lock:
#       old = self._value
#       self._value = value
#       return old
# 
#   def compareExchange(self, value, expected):
#     with self.lock:
#       old = self._value
# 
#       if old == expected:
#         self._value = value
# 
#       return old
# 
#   def inc(self, by=1):
#     with self.lock:
#       self._value += by
#       return self.value
# 
#   def dec(self, by=1):
#     with self.lock:
#       self._value -= by
#       return self.value


from rx.concurrency import Atomic
from collections import deque

class Disposable(object):
  """Represents a disposable object"""

  def dispose(self):
    pass

  def __enter__(self):
    return self

  def __exit__(self, exc_type, exc_value, traceback):
    self.dispose()

  @staticmethod
  def create(action):
    return AnonymouseDisposable(action)

  @staticmethod
  def empty():
    return disposableEmpty

disposableEmpty = Disposable()


class Cancelable(Disposable):
  """Inherits :class:`Disposable` and adds the :attr:`isDisposed` attribute."""

  def __init__(self):
    super(Cancelable, self).__init__()

# Path: rx/concurrency.py
# class Atomic:
#   def __init__(self, value=None, lock=RLock()):
#     self.lock = lock
#     self._value = value
# 
#   def value():
#       doc = "The value property."
#       def fget(self):
#           return self._value
#       def fset(self, value):
#           self.exchange(value)
#       return locals()
#   value = property(**value())
# 
#   def exchange(self, value):
#     with self.lock:
#       old = self._value
#       self._value = value
#       return old
# 
#   def compareExchange(self, value, expected):
#     with self.lock:
#       old = self._value
# 
#       if old == expected:
#         self._value = value
# 
#       return old
# 
#   def inc(self, by=1):
#     with self.lock:
#       self._value += by
#       return self.value
# 
#   def dec(self, by=1):
#     with self.lock:
#       self._value -= by
#       return self.value


# Path: rx/disposable.py
from rx.concurrency import Atomic
from collections import deque


class Disposable(object):
  """Represents a disposable object"""

  def dispose(self):
    pass

  def __enter__(self):
    return self

  def __exit__(self, exc_type, exc_value, traceback):
    self.dispose()

  @staticmethod
  def create(action):
    return AnonymouseDisposable(action)

  @staticmethod
  def empty():
    return disposableEmpty

disposableEmpty = Disposable()


class Cancelable(Disposable):
  """Inherits :class:`Disposable` and adds the :attr:`isDisposed` attribute."""

  def __init__(self):
    super(Cancelable, self).__init__()

    self._isDisposed = Atomic(False)