# Path: rx/notification.py
# class Notification(object):
#   """Represents a notification to an observer."""
# 
#   KIND_NEXT = 0
#   KIND_ERROR = 1
#   KIND_COMPLETED = 2
# 
#   def __eq__(self, other):
#     if not isinstance(other, Notification):
#       return False
# 
#     return (
#       self.kind == other.kind and
#       self.value == other.value and
#       self.hasValue == other.hasValue and
#       self.exception == other.exception
#     )
# 
#   def accept(self, observerOrOnNext, onError=None, onCompleted=None):
#     """Accepts an observer or the methods onNext, onError, onCompleted and invokes
#     either onNext, onError, onCompleted depending on which type of :class:`Notification`
#     it is. This is an abstract method that is implemented by
#     :class:`OnNextNotification`, :class:`OnErrorNotification`,
#     and :class:`OnCompletedNotification`."""
#     # if observerOrOnNext == None or hasattr(observerOrOnNext, '__call__'):
#     #   observer = Observer.create(observerOrOnNext, onError, onComplete)
#     raise NotImplementedError()
# 
#   @staticmethod
#   def createOnNext(value):
#     return OnNextNotification(value)
# 
#   @staticmethod
#   def createOnError(exception):
#     return OnErrorNotification(exception)
# 
#   @staticmethod
#   def createOnCompleted():
#     return OnCompletedNotification()
# 
# Path: rx/observable.py
# class PushToPullAdapter(object):
#   def __init__(self, source):
#     self.source = source
# 
#   def __iter__(self):
#     d = SingleAssignmentDisposable()
#     res = self.run(d)
#     d.disposable = self.source.subscribeSafe(res)
#     return res
# 
#   def run(self, subscription):
#     raise NotImplementedError()


from rx.notification import Notification
from rx.observable import PushToPullAdapter
from threading import RLock, BoundedSemaphore
import rx.linq.sink
        self.kind = Notification.KIND_ERROR
        self.error = exception

      if lackedValue:
        self.semaphore.release()

    def onCompleted(self):
      self.dispose()
      lackedValue = False

      with self.gate:
        lackedValue = not self.notificationAvailable
        self.notificationAvailable = True
        self.kind = Notification.KIND_COMPLETED

      if lackedValue:
        self.semaphore.release()

    def tryMoveNext(self):
      kind = None
      value = None
      error = None

      self.semaphore.acquire()

      with self.gate:
        kind = self.kind

        if kind == Notification.KIND_NEXT:
          value = self.value

# Path: rx/notification.py
# class Notification(object):
#   """Represents a notification to an observer."""
# 
#   KIND_NEXT = 0
#   KIND_ERROR = 1
#   KIND_COMPLETED = 2
# 
#   def __eq__(self, other):
#     if not isinstance(other, Notification):
#       return False
# 
#     return (
#       self.kind == other.kind and
#       self.value == other.value and
#       self.hasValue == other.hasValue and
#       self.exception == other.exception
#     )
# 
#   def accept(self, observerOrOnNext, onError=None, onCompleted=None):
#     """Accepts an observer or the methods onNext, onError, onCompleted and invokes
#     either onNext, onError, onCompleted depending on which type of :class:`Notification`
#     it is. This is an abstract method that is implemented by
#     :class:`OnNextNotification`, :class:`OnErrorNotification`,
#     and :class:`OnCompletedNotification`."""
#     # if observerOrOnNext == None or hasattr(observerOrOnNext, '__call__'):
#     #   observer = Observer.create(observerOrOnNext, onError, onComplete)
#     raise NotImplementedError()
# 
#   @staticmethod
#   def createOnNext(value):
#     return OnNextNotification(value)
# 
#   @staticmethod
#   def createOnError(exception):
#     return OnErrorNotification(exception)
# 
#   @staticmethod
#   def createOnCompleted():
#     return OnCompletedNotification()
# 
# Path: rx/observable.py
# class PushToPullAdapter(object):
#   def __init__(self, source):
#     self.source = source
# 
#   def __iter__(self):
#     d = SingleAssignmentDisposable()
#     res = self.run(d)
#     d.disposable = self.source.subscribeSafe(res)
#     return res
# 
#   def run(self, subscription):
#     raise NotImplementedError()


# Path: rx/linq/latest.py
from rx.notification import Notification
from rx.observable import PushToPullAdapter
from threading import RLock, BoundedSemaphore
import rx.linq.sink

        self.kind = Notification.KIND_ERROR
        self.error = exception

      if lackedValue:
        self.semaphore.release()

    def onCompleted(self):
      self.dispose()
      lackedValue = False

      with self.gate:
        lackedValue = not self.notificationAvailable
        self.notificationAvailable = True
        self.kind = Notification.KIND_COMPLETED

      if lackedValue:
        self.semaphore.release()

    def tryMoveNext(self):
      kind = None
      value = None
      error = None

      self.semaphore.acquire()

      with self.gate:
        kind = self.kind

        if kind == Notification.KIND_NEXT:
          value = self.value

        elif kind == Notification.KIND_ERROR: