# 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
      with self.gate:
        self.kind = Notification.KIND_COMPLETED

      if self.waiting:
        self.semaphore.release()

      self.waiting = False

    def tryMoveNext(self):
      with self.gate:
        self.waiting = True
        done = self.kind != Notification.KIND_NEXT

      if not done:
        self.semaphore.acquire()
      #
      # When we reach this point, we released the lock and got the next notification
      # from the observer. We assume no concurrent calls to the TryMoveNext method
      # are made (per general guidance on usage of IEnumerable<T>). If the observer
      # enters the lock again, it should have quit it first, causing _waiting to be
      # set to false, hence future accesses of the lock won't set the _kind, _value,
      # and _error fields, until TryMoveNext is entered again and _waiting is reset
      # to true. In conclusion, the fields are stable for read below.
      #
      # Notice we rely on memory barrier acquire/release behavior due to the use of
      # the semaphore, not the lock (we're still under the lock when we release the
      # semaphore in the On* methods!).
      #
      kind = self.kind


# 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/next.py
from rx.notification import Notification
from rx.observable import PushToPullAdapter
from threading import RLock, BoundedSemaphore
import rx.linq.sink

      with self.gate:
        self.kind = Notification.KIND_COMPLETED

      if self.waiting:
        self.semaphore.release()

      self.waiting = False

    def tryMoveNext(self):
      with self.gate:
        self.waiting = True
        done = self.kind != Notification.KIND_NEXT

      if not done:
        self.semaphore.acquire()
      #
      # When we reach this point, we released the lock and got the next notification
      # from the observer. We assume no concurrent calls to the TryMoveNext method
      # are made (per general guidance on usage of IEnumerable<T>). If the observer
      # enters the lock again, it should have quit it first, causing _waiting to be
      # set to false, hence future accesses of the lock won't set the _kind, _value,
      # and _error fields, until TryMoveNext is entered again and _waiting is reset
      # to true. In conclusion, the fields are stable for read below.
      #
      # Notice we rely on memory barrier acquire/release behavior due to the use of
      # the semaphore, not the lock (we're still under the lock when we release the
      # semaphore in the On* methods!).
      #
      kind = self.kind


      if kind == Notification.KIND_NEXT: