# 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
# class CompositeDisposable(Cancelable):
#   """Represents a group of disposable resources that
#   are disposed together"""
# 
#   def __init__(self, *disposables):
#     super(CompositeDisposable, self).__init__()
# 
#     if len(disposables) == 0:
#       self.disposables = []
#     elif len(disposables) == 1 and not isinstance(disposables[0], Disposable):
#       self.disposables = [d for d in disposables[0] if d != None]
#     else:
#       self.disposables = [d for d in disposables if d != None]
# 
#     self.length = len(self.disposables)
# 
#   def add(self, disposable):
#     shouldDispose = False
# 
#     with self.lock:
#       shouldDispose = self.isDisposed
# 
#       if not shouldDispose:
#         self.disposables.append(disposable)
#         self.length += 1
# 
#     if shouldDispose:
#       disposable.dispose()
# 
#   def contains(self, disposable):
#     with self.lock:
#       return self.disposables.index(disposable) >= 0
# 
#   def remove(self, disposable):
#     shouldDispose = False
# 
#     with self.lock:
#       if self.isDisposed:
#         return False
# 
#       index = self.disposables.index(disposable)
# 
#       if index < 0:
#         return False
# 
#       shouldDispose = True
# 
#       self.disposables.remove(disposable)
#       self.length -= 1
# 
#     if shouldDispose:
#       disposable.dispose()
# 
#     return shouldDispose
# 
#   def clear(self):
#     disposables = []
# 
#     with self.lock:
#       disposables = self.disposables
#       self.disposables = []
#       self.length = 0
# 
#     for disposable in disposables:
#       disposable.dispose()
# 
#   def dispose(self):
#     if not self._isDisposed.exchange(True):
#       self.clear()
# 
# Path: rx/observable.py
# class Producer(Observable):
#   """Base class for implementation of query operators, providing
#   performance benefits over the use of Observable.Create"""
# 
#   def subscribeCore(self, observer):
#     return self.subscribeRaw(observer, True)
# 
#   def subscribeRaw(self, observer, enableSafequard):
#     sink = SingleAssignmentDisposable()
#     subscription = SingleAssignmentDisposable()
# 
#     d = CompositeDisposable(sink, subscription)
# 
#     if enableSafequard:
#       observer = AutoDetachObserver(observer, d)
# 
#     def assignSink(s):
#       sink.disposable = s
# 
#     def scheduled():
#       subscription.disposable = self.run(observer, subscription, assignSink)
#       return Disposable.empty()
# 
#     if Scheduler.currentThread.isScheduleRequired():
#       Scheduler.currentThread.schedule(scheduled)
#     else:
#       scheduled()
# 
#     return d
# 
#   def run(self, observer, cancel, setSink):
#     raise NotImplementedError()


from rx.concurrency import Atomic
from rx.disposable import CompositeDisposable
from rx.observable import Producer
import rx.linq.sink

  def omega(self, count):
    return SkipCount(self.source, self.count + count)

  def run(self, observer, cancel, setSink):
    sink = self.Sink(self, observer, cancel)
    setSink(sink)
    return self.source.subscribeSafe(sink)

  class Sink(rx.linq.sink.Sink):
    def __init__(self, parent, observer, cancel):
      super(SkipCount.Sink, self).__init__(observer, cancel)
      self.parent = parent
      self.remaining = parent.count

    def onNext(self, value):
      if self.remaining <= 0:
        self.observer.onNext(value)
      else:
        self.remaining -= 1

    def onError(self, exception):
      self.observer.onError(exception)
      self.dispose()

    def onCompleted(self):
      self.observer.onCompleted()
      self.dispose()



# 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
# class CompositeDisposable(Cancelable):
#   """Represents a group of disposable resources that
#   are disposed together"""
# 
#   def __init__(self, *disposables):
#     super(CompositeDisposable, self).__init__()
# 
#     if len(disposables) == 0:
#       self.disposables = []
#     elif len(disposables) == 1 and not isinstance(disposables[0], Disposable):
#       self.disposables = [d for d in disposables[0] if d != None]
#     else:
#       self.disposables = [d for d in disposables if d != None]
# 
#     self.length = len(self.disposables)
# 
#   def add(self, disposable):
#     shouldDispose = False
# 
#     with self.lock:
#       shouldDispose = self.isDisposed
# 
#       if not shouldDispose:
#         self.disposables.append(disposable)
#         self.length += 1
# 
#     if shouldDispose:
#       disposable.dispose()
# 
#   def contains(self, disposable):
#     with self.lock:
#       return self.disposables.index(disposable) >= 0
# 
#   def remove(self, disposable):
#     shouldDispose = False
# 
#     with self.lock:
#       if self.isDisposed:
#         return False
# 
#       index = self.disposables.index(disposable)
# 
#       if index < 0:
#         return False
# 
#       shouldDispose = True
# 
#       self.disposables.remove(disposable)
#       self.length -= 1
# 
#     if shouldDispose:
#       disposable.dispose()
# 
#     return shouldDispose
# 
#   def clear(self):
#     disposables = []
# 
#     with self.lock:
#       disposables = self.disposables
#       self.disposables = []
#       self.length = 0
# 
#     for disposable in disposables:
#       disposable.dispose()
# 
#   def dispose(self):
#     if not self._isDisposed.exchange(True):
#       self.clear()
# 
# Path: rx/observable.py
# class Producer(Observable):
#   """Base class for implementation of query operators, providing
#   performance benefits over the use of Observable.Create"""
# 
#   def subscribeCore(self, observer):
#     return self.subscribeRaw(observer, True)
# 
#   def subscribeRaw(self, observer, enableSafequard):
#     sink = SingleAssignmentDisposable()
#     subscription = SingleAssignmentDisposable()
# 
#     d = CompositeDisposable(sink, subscription)
# 
#     if enableSafequard:
#       observer = AutoDetachObserver(observer, d)
# 
#     def assignSink(s):
#       sink.disposable = s
# 
#     def scheduled():
#       subscription.disposable = self.run(observer, subscription, assignSink)
#       return Disposable.empty()
# 
#     if Scheduler.currentThread.isScheduleRequired():
#       Scheduler.currentThread.schedule(scheduled)
#     else:
#       scheduled()
# 
#     return d
# 
#   def run(self, observer, cancel, setSink):
#     raise NotImplementedError()


# Path: rx/linq/skip.py
from rx.concurrency import Atomic
from rx.disposable import CompositeDisposable
from rx.observable import Producer
import rx.linq.sink


  def omega(self, count):
    return SkipCount(self.source, self.count + count)

  def run(self, observer, cancel, setSink):
    sink = self.Sink(self, observer, cancel)
    setSink(sink)
    return self.source.subscribeSafe(sink)

  class Sink(rx.linq.sink.Sink):
    def __init__(self, parent, observer, cancel):
      super(SkipCount.Sink, self).__init__(observer, cancel)
      self.parent = parent
      self.remaining = parent.count

    def onNext(self, value):
      if self.remaining <= 0:
        self.observer.onNext(value)
      else:
        self.remaining -= 1

    def onError(self, exception):
      self.observer.onError(exception)
      self.dispose()

    def onCompleted(self):
      self.observer.onCompleted()
      self.dispose()



class SkipTime(Producer):